我有一個集合:MongoDB的更新/陣列的Upsert準確匹配
我希望能夠以更新的標準定數組的數組的統計信息的文件(精確匹配)。
我嘗試這樣做2個階段:
db.gStats.update({
"criteria" : {$size : 2},
"criteria" : {$all : [{"key1" : "2096955"},{"value1" : "2015610"}]}
},
{
$pull : {groups : {"id" : "XXXX"}}
}
)
推新文件
db.gStats.findAndModify({
query : {
"criteria" : {$size : 2},
"criteria" : {$all : [{"key1" : "2015610"}, {"key2" : "2096955"}]}
},
update : {
$push : {groups : {"id" : "XXXX", "visited" : 29, "liked" : 144}}
},
upsert : true
})
的:
從給定的 「ID」 的陣列拉統計文件拉查詢完美。
2014-12-13T15:12:58.571+0100 findAndModifyFailed failed: {
"value" : null,
"errmsg" : "exception: Cannot create base during insert of update. Cause
d by :ConflictingUpdateOperators Cannot update 'criteria' and 'criteria' at the
same time",
"code" : 12,
"ok" : 0
} at src/mongo/shell/collection.js:614
請注意,對於'criteria'上的兩個條件,您不需要'$和'。條件可以按照「條件」來構造:{「$ size」:2,「$ all」:[{「key1」:「2015610」},{「key2」:「2096955」}]}' – wdberkeley 2014-12-15 17:25:20