db.collection.update( ) all documents
db.collectionname.update( { "field" : "oldvalue" }, { $set:{ "field" : "newvalue" } }, { multi : true } );
Since MongoDB 3.2, you can use this shorter syntax:
db.coll.updateMany({}, {$rename: {'originField': "newField"}})
All updates in MongoDB are, by default, singular. You must add a third option to your command to make:
db.coll.update({},{ $rename: {'originField':'newField'} }, {multi:true});
If you are using 3.2 and above you can use updateMany()
:
db.coll.updateMany({}, {$rename: {'originField': "newField"}})