CosmosDB - 无效的BSON字段名称'places。$ id'

时间:2017-09-01 19:04:16

标签: mongodb azure azure-cosmosdb

我在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

如果有人知道最新情况,我真的很感激。

1 个答案:

答案 0 :(得分:0)

你应该替换

"places":{"$ref":"places","$id": original_id},

"places_id": original_id,