2

可以使用 N1QL 吗?

例如我有这个:

{
"blog": "Coffee",
"user_id": 41,
"comments": [
    {
        "comment": "cup",
        "user_id": 883
    },
    {
        "comment": "water",
        "user_id": 790
    }
  ]
}

我想使用 N1QL 在评论中添加糖,结果如下: { "blog": "Coffee", "user_id": 41, "comments": [ { "comment": "cup", "user_id": 883 }, {“评论”:“水”,“user_id”:790 },{“评论”:“糖”,“user_id”:14 }] }

我试过这个:

UPDATE
    Blog
SET
    `c.comment` = "sugar",
    `c.user_id` = 14
FOR
    c IN comments
WHERE 
    `blog` = "Coffee" 
// [{"code":3000,"msg":"syntax error - at WHERE"}

和这个:

UPDATE 
    Blog
SET
    ("comments", { "comment": "sugar", "user_id": 14})
WHERE
    `blog` = "Coffee"
//[{"code":3000,"msg":"syntax error - at ("}
4

1 回答 1

5

是的,您可以使用 N1QL 进行任何修改。

UPDATE Blog
SET comments = ARRAY_APPEND( comments, { "comment":"sugar", "user_id":14 } )
WHERE blog = "Coffee";
于 2016-05-16T17:32:54.040 回答