Couchbase N1QL:嵌套文档更新

Couchbase N1QL: Update on nested Documents

当有这样的嵌套文档时:

{
"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"
    }
  ]
}

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

UPDATE Blog SET rank = "top blog" WHERE blog = "testblog1";

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

更新博客
SET c.ranking = "top comment" FOR c IN comments WHEN c.comment = "testcomment2" END
WHERE 博客 = "testblog1"