I have a document
"watched": {
"1": true,
"2": true, //should add 3 with true value
},
"fans": 4 //should increment by 5 it should be 9
when ever I do update it should increase the key and value and update the fans increment by 5
db.getCollection('movies').updateOne({
_id: Object_id("60e80c96b9c55e7a01898f5c")
}, { $set: { "watched.3": true} } },
{ $inc: { fans: 5 } }
)
EITHER it does update or increment how to manage both
CodePudding user response:
db.collection.update({
_id: ObjectId("60e80c96b9c55e7a01898f5c"),
"watched.3": {
$exists: false
}
},
{
$set: {
"watched.3": true
},
$inc: {
fans: 5
}
})
