MongoDB Tips and Snippets
A sort of "cheat-sheet" full of useful tips and snippets...
Rename a field
Add a new field
In case you want to add a new_field to all your collection, you have to use empty selector, and set multi flag to true (last param) to update all the documents
Upsert: If set to true, creates a new document when no document matches the query criteria.
Multi: If set to true, updates multiple documents that meet the query criteria. If set to false, updates one document.
No value:
Empty array:
Find Documents Missing a Given Field
or
Remove a Field
Delete a Document
Typically, you'd want to delete only by the document's unique _id
, but it can also be done in the same way by some other known field value:
Last updated