Tuesday, 7 June 2016

Inserting a filed:

Inserting a field is pretty easier:
db.collectionname.update(
               {},
               {$set:{key:value},false,true}
               )

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.
db.collectionname.update(
               {},
               {$set:{key:value},{upsert:false,multi:true}}
               )