測試數(shù)據(jù):{ "_id" : ObjectId("4b97e62bf1d8c7152c9ccb74"), "title" :
"ABC",
"comments" : [ { "by" : "joe", "votes" : 3 }, { "by" : "jane",
"votes" : 7 } ] }執(zhí)行更新語句:語句一:db.mydb.update({title:"ABC"}, {$inc:{"comments.$.votes":1}}, 0, 1)執(zhí)行報錯:Cannot apply the positional operator without a corresponding query field containing an array.語句二:db.mydb.update({"comments.by":"joe"}, {$inc:{"comments.$.votes":1}}, 0, 1)
為什么會執(zhí)行結(jié)果正常 請問是怎么回事?
慕標(biāo)琳琳
2023-04-30 15:11:48