Update specific object in the array of object in couchbase 4.1

北城余情 提交于 2019-12-12 02:21:52

问题


I have following doc with doc key cart::16

 {
        "_type": "NSCart",
        "_metadata": {
               "created_at": 1473075845614,
               "updated_at": null
        },
        "_id": "f28bc609-6aba-47e5-8e83-5bee2397566f",
        "userId": "B1HvmsLj57c9235c",
        "items" : [{
               "itemId": "N1d55j8m4xr",
               "seller": "ByD9T4Ks57cbbd8e",
               "license": null,
               "basePrice": 0
             },{
              "itemId": "L9nd6Dswl4v",
              "seller": "ByD9T4Ks57cbbd8e",
              "license": E122,
              "basePrice": 500,
              "eCharge": 10,
              "total": 510
        }]
 }

now i want to update a doc where item id is N1d55j8m4xr like this

{
      "itemId": "N1d55j8m4xr",
      "seller": "ByD9T4Ks57cbbd8e",
      "license": null,
      "basePrice": 590,
      "eCharge": 18,
      "total": 608
}

There is method array_replace in n1ql but didn't get desired output.


回答1:


Use the following syntax from the N1QL documentation.

UPDATE mybucket SET x.field = newvalue FOR x IN myarray WHEN x.id = myid END;


来源:https://stackoverflow.com/questions/39331437/update-specific-object-in-the-array-of-object-in-couchbase-4-1

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