mongodb - How to fill missing field with data to existing documents in mongo db? -
i have documents like
[{ _id:.., mailtitle:"hello", broadcastmessage:"how u"}] [{ _id:.., mailtitle:"hello john", broadcastmessage:"how u john"}] [{ _id:.., mailtitle:"hello", broadcastmessage:"how u john", user_id:"1", datesent:"12/12/2016" }]
now want add user_id:"1", datesent:"12/12/2016" first 2 , others documents.
please help!!!
using update (deprecated) :
db.collection.update( { "user_id": {$exists: false}, "datesent": {$exists: false} }, { $set: { user_id : 1, datesent: "12/12/2016", (use utc date object instead of string) } }, { multi: true } );
using updatemany :
db.collection.updatemany( { "user_id": {$exists: false}, "datesent": {$exists: false} }, { $set: { user_id : 1, datesent: "12/12/2016", (use utc date object instead of string) } } );
the above pick documents don't have field called user_id
, datesent
, , set fields. hope helps.
Comments
Post a Comment