1db.mycollection.find({}).forEach((doc, index) => {
2 doc.myStr = doc.myStr.replace('foo', 'bar');
3 db.mycollection.save(doc);
4});
1try {
2 db.restaurant.replaceOne(
3 { "name" : "Central Perk Cafe" },
4 { "name" : "Central Pork Cafe", "Borough" : "Manhattan" }
5 );
6} catch (e){
7 print(e);
8}
9
1db.collection.replaceOne(
2 <filter>,
3 <replacement>,
4 {
5 upsert: <boolean>,
6 writeConcern: <document>,
7 collation: <document>,
8 hint: <document|string> // Available starting in 4.2.1
9 }
10)
11