Skip to content
This repository has been archived by the owner on Oct 18, 2021. It is now read-only.

CRUD Spec and Basic Insert/Update/Delete write commands #48

Merged
merged 7 commits into from
Jun 16, 2015

Conversation

kyeah
Copy link
Contributor

@kyeah kyeah commented Jun 15, 2015

This PR fills the CRUD spec for collections, except for Errors, and implements the basic insert, update, and delete write commands without ObjectID generation. The coll module is now separated into coll, coll::options, and coll::results.

Other small updates (sorry):

  • db: Added the drop_collection() function.
  • connstring: Converted to using BTreeMap over HashMap. The standard HashMap implementation uses a secure crypto hash algorithm that makes it perform significantly slower than BTreeMap.
  • Cargo.toml: Updated to use the insertion-order implementation of BSON documents, necessary for command ops.

The travis environment has been configured as per @saghmrossi's fix in #47 , but it will fail until we get 3.0 testing up and running.

Fill CRUD spec for collections; use BTreeMap
Added drop collection
Delete commands
Complete write commands with tests
Reorganize coll module and fix test warnings
Documentation and cargo toml update
};

let req = try!(Message::with_query(self.get_req_id(), flags, self.namespace.to_owned(),
options.skip as i32, options.limit, doc, options.projection));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason why skip isn't being stored as an i32 in all of the options structs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skip can't be negative (as per @alabid), but the server still takes it as i32. u32 prevents it on the client-side. However, perhaps it should be stored as i32 to follow spec?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about in CountOptions, where it's 64-bits?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same deal with unsigned; 64-bit count options are specified in the spec.

};

let flags = OpQueryFlags {
tailable_cursor: options.cursor_type != CursorType::NonTailable,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should really have a function to abstract away this logic and the logic on L105. Would be handy to have a constructor that abstracts away this != and == stuff

@vkarpov15
Copy link
Contributor

Couple small comments. Excellent work overall!

@steveklabnik, comments on the general rustyness of this code would be much appreciated. This implements a lot of the basic functionality we want out of a mongodb driver - inserts, updates, etc.

@vkarpov15
Copy link
Contributor

Sweet. Can you fix the merge conflict please @kyeah ?

@steveklabnik
Copy link

I will check out the 'general rustiness' soon :)

/// Extracts the collection name from the namespace.
pub fn name(&self) -> String {
match self.namespace.find(".") {
Some(idx) => self.namespace[idx+1..].to_owned(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

careful with this. This is a byte index of these strings, are you guaranteed that this is actually correct? Can namespaces have non-ascii characters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the best way to grab a non-ascii substring? http://is.gd/PIX31l19 (via Rust forum)?

assert_eq!(4, results.len());

// Assert director attributes
for i in 0..3 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test assertions in for loops are very difficult to debug because the line number doesn't exactly correspond to the assertion error (doesn't tell you which value of loop variable the tests failed). Can you flatten this out? As a general rule of thumb, for and if should not be in test code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kyeah can you address this in a separate PR? Don't want to block y'all anymore on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, working on it now and there's a bug in the update_many test, will open a new PR.

vkarpov15 added a commit that referenced this pull request Jun 16, 2015
CRUD Spec and Basic Insert/Update/Delete write commands
@vkarpov15 vkarpov15 merged commit 5475dfe into mongodb-labs:1.0 Jun 16, 2015
@kyeah kyeah deleted the write_commands branch June 18, 2015 20:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants