我想一次对多个子文档进行更新查询。我会将所有子文档状态设置为被动,只要它们满足我在查询时给出的条件。
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" }});
上面的查询恰好找到了一个子文档,然后根据我的需要进行更新。但;
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" }});
当我用或填充查询段并添加其他项目时,它会给出错误:
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"
}
})
我在这里想念什么?