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
Upsert option not working #120
Comments
I've only ever used upsert with the Also I think errors are handled as exceptions now ( |
I do use the try/catch construction. The error message is: BulkWrite error. The code is:
What am I doing wrong. Can you perhaps give me some example code that works, that would really help 😉 |
If you're not using update operators, you're not updating a document but replacing it. Thus, use the |
That seems to do the trick.
Thanks! |
@alcaeus provides the right answer. I'm marking this as closed. The library's documentation at http://mongodb.github.io/mongo-php-library/classes/collection/#crud-operations says "CRUD is an acronym for Create, Read, Update, and Delete. The Collection class implements MongoDB’s cross-driverCRUD specification, which defines a common API for collection-level read and write methods." It links to https://github.com/mongodb/specifications/blob/master/source/crud/crud.rst#update-vs-replace-validation, which discusses the differences between update and replace. I do think, that the library's documentation should be improved on this. It's in the repository at https://github.com/mongodb/mongo-php-library/blob/master/docs/classes/collection.md#crud-operations if you want to give this a shot yourself. |
Created PHPLIB-178 to track this task. |
I have implemented this new library and the save function is deprecated. I wan't to use the insertOne with the upsert option, but it fails.
This will return a BulkWrite error with code 0 and no message.
What is wrong with the code?
The text was updated successfully, but these errors were encountered: