測試數據:{"_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)執行報錯:Cannotapplythepositionaloperatorwithoutacorrespondingqueryfieldcontaininganarray.語句二:db.mydb.update({"comments.by":"joe"},{$inc:{"comments.$.votes":1}},0,1)執行結果正常請問是怎么回事?
mongodb "$" 操作符問題
楊__羊羊
2019-04-06 16:57:39