How to add new field to all documents in mongoDB?

As you know that mongoDB have a update function which have four parameter to pass.

You can use this like below:
db.coll.update({}, $set:{name:"value"}, false, true);
 
You can set condition too:
db.coll.update({_id:12}, $set:{name:"value"}, false, true);

Comments