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