I want to make an update query for multiple subdocuments at once. I will be setting all the subdocuments statuses to passive where they satisfy the condition I give on query.
db.deduplications.update(
{ $and: [
{ "_id": "189546D623FC69E3B693FDB679DBC76C" },
{ "DeviceVersionPairs.DeviceId": ObjectId("5822d0606bfdcd6ec407d9b9") },
{ "DeviceVersionPairs.CloudFolderId": ObjectId("5823110e6bfdd46ec4357582") },
{ "DeviceVersionPairs.CloudFileId": ObjectId("582311168cd396223499942a") },
{ "DeviceVersionPairs.VersionId": ObjectId("582311168cd396223499942b") }
] },
{ $set: { "DeviceVersionPairs.$.Status": "passive" }});
Above query finds exactly one subdocument, then it makes the update as I want it. But;
db.deduplications.update(
{ $or: [ { $and: [
{ "_id": "189546D623FC69E3B693FDB679DBC76C" },
{ "DeviceVersionPairs.DeviceId": ObjectId("5822d0606bfdcd6ec407d9b9") },
{ "DeviceVersionPairs.CloudFolderId": ObjectId("5823110e6bfdd46ec4357582") },
{ "DeviceVersionPairs.CloudFileId": ObjectId("582311168cd396223499942a") },
{ "DeviceVersionPairs.VersionId": ObjectId("582311168cd396223499942b") }
] } ,
{ $and: [
{ "_id": "189546D623FC69E3B693FDB679DBC76C" },
{ "DeviceVersionPairs.DeviceId": ObjectId("56dfe1356caaea14a819f1e4") },
{ "DeviceVersionPairs.CloudFolderId": ObjectId("583fb4bc6e7f341874f13bfc") },
{ "DeviceVersionPairs.CloudFileId": ObjectId("583fb539e015b8a53fb71872") },
{ "DeviceVersionPairs.VersionId": ObjectId("583fb4ca6e7f331874213584") }
] } ] },
{ $set: { "DeviceVersionPairs.$.Status": "passive" }});
When I populate the query segment with an or, and add the other items it gives error:
WriteResult({
"nMatched" : 0,
"nUpserted" : 0,
"nModified" : 0,
"writeError" : {
"code" : 16837,
"errmsg" : "The positional operator did not find the match needed from the query. Unexpanded update: DeviceVersionPairs.$.Status"
}
})
What am I missing here?