拥有这样的嵌套文档时:
{
"blog": "testblog1",
"user_id": 41,
"comments": [
{
"comment": "testcomment1",
"user_id": 883
},
{
"comment": "testcomment2",
"user_id": 790
}
]
}
可以使用N1QL进行更新操作以向子文档添加额外的字段吗?
我想将字段"ranking" : "top comment"
添加到带有注释testcomment2的子文档中:
{
"blog": "testblog1",
"user_id": 41,
"comments": [
{
"comment": "testcomment1",
"user_id": 883
},
{
"comment": "testcomment2",
"user_id": 790,
"ranking" : "top comment"
}
]
}
网站注意:以下语句会在收集博客上的根文档中添加一个字段:
UPDATE Blog SET rank = "top blog" WHERE blog = "testblog1";
答案 0 :(得分:10)
是的,您可以在N1QL中执行以下操作:
更新博客
SET c.ranking ="热门评论" FOR c IN comments cENment =" testcomment2"结束
博客=" testblog1"