Mongo db update query is not working in embedded documents in azure cosmos db

偶尔善良 提交于 2019-12-20 06:17:18

问题


Embedded Update query works fine in mlab and atlas but not working in Cosmos DB:

My Collection structure:

{
    "_id" : ObjectId("5982f3f97729be2cce108785"),
    "password" : "$2y$10$F2P9ITmyKNebpoDaQ1ed4OxxMZSKmKFD9ipiU1klqio239c/nJcme",
    "nin" : "123",
    "login_status" : 1,
    "updated_at" : ISODate("2017-05-16T09:09:03.000Z"),
    "created_at" : ISODate("2017-05-16T06:08:47.000Z"),
    "files" : [ 
        {
            "name" : "abc",
            "updated_at" : ISODate("2017-05-16T06:08:48.000Z"),
            "created_at" : ISODate("2017-05-16T06:08:48.000Z"),
            "_id" : ObjectId("5982f3f97729be2cce108784")
        }
    ],
    "name" : "demo",
    "email" : "email@gmail.com",
    "phone" : "1231234",

}

My query is:

db.rail_zones.update(
  {'_id': ObjectId("5982f3f97729be2cce108785"),
   'files._id' : ObjectId("5982f3f97729be2cce108784")},
  { $set: {'files.$.name' : "Changed"}})

I get this response:

"acknowledged" : true,
"matchedCount" : 0.0,
"modifiedCount" : 0.0

回答1:


According to your description, I tested this issue on my side and found the Array Update could not work as expected. I assumed that the Array Update feature has not been implemented in the MongoDB Compatibility layer of Azure CosmosDB. Moreover, I found a feedback Positional array update via '$' query support talking about the similar issue.



来源:https://stackoverflow.com/questions/45481768/mongo-db-update-query-is-not-working-in-embedded-documents-in-azure-cosmos-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!