2
我想更新現有的文檔,其中有一個空值的字段,我得到以下錯誤。
文件:
{
"_id" : ObjectId("582299f71e21dbf65027325e"),
"b" : "5555",
"f" : null
}
查詢:
db.getCollection('temp').update({"b":"5555"},{"$set":{"f.1.b":1,"f.2.b":2}})
錯誤:
WriteResult({
"nMatched" : 0,
"nUpserted" : 0,
"nModified" : 0,
"writeError" : {
"code" : 16837,
"errmsg" : "cannot use the part (f of f.1.b) to traverse the element ({f: null})"
}
})
誰能告訴我,爲什麼它是不更新文檔中的值。
謝謝。
它工作正常,如果我的目標是零和在有些值已經存在的情況下,它將取代現有的對象。感謝您的回答。 – Prabhakaran
歡迎你,如果你有解決方案,你可以打勾標記這個答案,感謝 –