Sunday, February 5, 2023

Mongo - Update field of records matching criteria

Main point is that we need to set multi: true 

db.getCollection("notificationcontent").find({})

db.getCollection("notificationcontent").update({"_id" : ObjectId("63be8e174826db2b41dc352b")},{"$set" : {"tags" : ["Inspirational" ] }})

db.getCollection("notificationcontent").update({"status" : "ready"},{"$set" : {"tags" : ["Inspirational" ] }})

db.getCollection("notificationcontent").update({"status" : "ready"},{"$set" : {"tags" : ["Inspirational" ] }},{upsert:false, multi:true})

references:


No comments:

Post a Comment