My collection (called "workers"):
"_id" : "500"
"type" : "Manager",
"employees" : [{
"name" : "bob"
"id" : 101
},{
"name" : "phil"
"id" : 102
}]
Goal: for every _id that is a type: Manager AND that contains a subdocument that has an "id" of 102: replace 102 with 202.
Desired End result:
"_id" : "500"
"type" : "Manager",
"employees" : [{
"name" : "bob"
"id" : 101
},{
"name" : "phil"
"id" : 202
}]
I have tried:
db.workers.update({type:'Manager','employees.id':'102'},{$set:{'employees.id':'202'}},{multi:true})
I then did the following two things to verify:
db.workers.find({type: "Manager", 'employees.id': 102}).count()
I get a result of 9.
I also tried this to verify:
db.workers.find({$and: [{type: "Manager"},{"employees.id":60}]}).count()
This returned 0.
I am pretty confused at this point. Is my update wrong? is my find wrong? Is it both? Is the '9' result wrong? Is the '0' wrong?