I have this code
{
"_id" : ObjectId("573308a2519d9ff8820e7be8"),
"id" : "Example",
"Test" : [
"InsertB1",
"InsertB2"
],
"num" : 2
}
I would like to use the function findAndUpdate
because I would like to
- Change
"InsertB1"
to"UpdateB1"
- increase the
"num"
from 2 to 3.
I've written this one, but does not work...
db.Collection.findAndModify({
query: {
id:"Example",
num:{ $lt: 3 }
},
update: {
id:"Example",
Test: "InsertB1",
$set: { "Test.$": "Update1" },
$inc: { num: 1 }
},
upsert:true,
new:true
})
How can I modify my code?