-
Notifications
You must be signed in to change notification settings - Fork 208
Split and modify CRUD examples #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
||
$mm = new \MongoDB\Manager("mongodb://server1,server2/?replicaSet=FOOBAR"); | ||
|
||
$results = $mm->executeWrite("db.collection", $batch, $writeOptions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than InsertBatch telling us that the operations are inserts (by its class name), I don't see why we shouldn't just pass in an array of operations. This would mean we'd have specific methods like executeInsert()
, which I think is fine. In the C code, it means there's no need to check the class and then branch off internally to the appropriate write method in libmongoc. Also, being able to pass an array of operations (e.g. documents to insert or the update arguments) in one shot addresses @derickr's concern about having a simple interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a classname makes it easier and cleaner to validate the actual operations.
Having to validate enormous array all the time is both complex and not something you want to have multiple branches of in one method.
Allow individual classes to provide their own validation and then simply be typehinted simplifies the entire chain of events and allows us to keep small pieces of selfcontained code.
Having an executeInsert(array($document1, $document2)); is begging for validation issues and "whops, I did executeInsert($document)"
Providing a \MongoDB\Manager\CRUD->insertOne($document); is a trivial wrapper though we could also provide as part of the extension as a simplified helper API....
$query = new \MongoDB\Query($criteria, $selector); | ||
$query | ||
->setOrderBy(array('name' => 1)) | ||
->setComment('More special stuff') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http://docs.mongodb.org/manual/reference/operator/query-modifier/#operators
What do we do with all the other operators?
$query->setOperator($name, $value) ? feels a tinybit weird...
looks good. |
No description provided.