我在MongoDB文档模型上使用Azure CosmoDB,我在使用DBRefs $id
更新某些文档时遇到了奇怪的行为看看这个脚本示例:
original_id = ObjectId()
db.places.insert({
"_id": original_id,
"name": "Broadway Center",
"url": "bc.example.net"
})
db.people.insert({
"name": "Erin",
"places":{"$ref":"places","$id": original_id},
"url": "bc.example.net/Erin"
})
db.people.find({"places.$id": original_id}) //works like charm
db.people.update({"places.$id": original_id}, {$set:{"NEW_FIELD": false}}, {multi:true}) //doesn't works =/
然后返回:
Failed to execute script.
Error: Error: error: {
"_t" : "OKMongoResponse",
"ok" : 0,
"code" : 2,
"errmsg" : "Invalid BSON field name 'places.$id'",
"$err" : "Invalid BSON field name 'places.$id'"
} :
DBCollection.prototype.update@src/mongo/shell/collection.js:589:23
@(shell):1:1
如果有人知道最新情况,我真的很感激。
答案 0 :(得分:0)
你应该替换
"places":{"$ref":"places","$id": original_id},
带
"places_id": original_id,