测试数据:
{ "_id" : ObjectId("4b97e62bf1d8c7152c9ccb74"), "title" : "ABC", "comments" : [ { "by" : "joe", "votes" : 3 }, { "by" : "jane", "votes" : 7 } ] }
执行更新语句:
语句一:
db.mydb.update({title:"ABC"}, {$inc:{"comments.$.votes":1}}, 0, 1)
执行报错: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)
holdtom
江户川乱折腾
相关分类