在Couchbase 4.1中更新对象数组中的特定对象 [英] Update specific object in the array of object in couchbase 4.1
本文介绍了在Couchbase 4.1中更新对象数组中的特定对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下文档及其文档密钥车:: 16
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
}]
}
现在我想像这样更新文档ID为N1d55j8m4xr的文档
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
}
n1ql中有array_replace方法,但未获得所需的输出.
There is method array_replace in n1ql but didn't get desired output.
推荐答案
使用N1QL文档中的以下语法.
Use the following syntax from the N1QL documentation.
UPDATE mybucket SET x.field = newvalue FOR x IN myarray WHEN x.id = myid END;
这篇关于在Couchbase 4.1中更新对象数组中的特定对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文