Couchbase N1QL:嵌套文档的更新

geh*_*uad 3 document nosql couchbase sql++

有这样的嵌套文档时:

{
"blog": "testblog1",
"user_id": 41,
"comments": [
    {
        "comment": "testcomment1",
        "user_id": 883
    },
    {
        "comment": "testcomment2",
        "user_id": 790
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

可以使用N1QL进行更新操作以向子文档添加额外的字段吗?

我想"ranking" : "top comment"使用注释testcomment2 将该字段添加到子文档:

{
"blog": "testblog1",
"user_id": 41,
"comments": [
    {
        "comment": "testcomment1",
        "user_id": 883
    },
    {
        "comment": "testcomment2",
        "user_id": 790,
        "ranking" : "top comment"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

站点注意:以下语句将向集合博客上的根文档添加一个字段:

UPDATE Blog SET rank = "top blog" WHERE blog = "testblog1";
Run Code Online (Sandbox Code Playgroud)

ger*_*dss 10

是的,您可以在N1QL中执行以下操作:

更新博客
SET c.ranking ="热门评论"FOR c IN评论时c.comment ="testcomment2"END
WHERE blog ="testblog1"