| Start |
|---|
Create Or The difference with Two new methods to insert documents into a collection, in MongoDB 3.2.x:- Use Use Note that |
| Update Update the entire object: Or just update a single field of a document. In this case You can also update multiple documents simultaneously by adding a third parameter. This query will update all documents where the name equals If a new field is coming for update, that field will be added to the document. If a document is needed to be replaced, can be used. Note: Fields you use to identify the object will be saved in the updated document. Field that are not defined in the update section will be removed from the document. |
| Delete Deletes all documents matching the query parameter: Or just one MongoDB's or |
| Read Query for all the docs in the Or just the first one: You can also specify which fields to return by passing a field selection parameter. The following will exclude the Note: by default, the & specify field too if required |
| More update operators You can use other operators besides The The |
| "multi" Parameter while updating multiple documents To update multiple documents in a collection, set the multi option to true. multi is optional. If set to true, updates multiple documents that meet the query criteria. If set to false, updates one document. The default value is false. db.mycol.find() { "_id" : ObjectId(598354878df45ec5), "title":"MongoDB Overview"} { "_id" : ObjectId(59835487adf45ec6), "title":"NoSQL Overview"} { "_id" : ObjectId(59835487adf45ec7), "title":"Tutorials Point Overview"} db.mycol.update({'title':'MongoDB Overview'}, {$set:{'title':'New MongoDB Tutorial'}},{multi:true}) |
| Update of embedded documents. For the following schema: Update Tom's marks to 55 where marks are 50 (Use the positional operator $): For the following schema: Update Tom's English marks to 85 : Explaining above example: By using {name: "Tom", "marks.subject": "English"} you will get the position of the object in the marks array, where subject is English. In "marks.$.marks", $ is used to update in that position of the marks array Update Values in an Array The positional $ operator identifies an element in an array to update without explicitly specifying the position of the element in the array. Consider a collection students with the following documents: To update 80 to 82 in the grades array in the first document, use the positional $ operator if you do not know the position of the element in the array: Syntax
RemarksUpdating and Deleting a document should be done carefully. Since operation may affect for multiple documents. |
Read Article
https://develop.horje.com/learn/1434/reference