是否可以使用N1QL?
例如我有这个:
{
"blog": "Coffee",
"user_id": 41,
"comments": [
{
"comment": "cup",
"user_id": 883
},
{
"comment": "water",
"user_id": 790
}
]
}
我想用N1QL添加糖来评论,结果如下: { “博客”:“咖啡”, “user_id”:41, “评论”: [ { “评论”:“杯子”, “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 ("}
答案 0 :(得分:5)
是的,您可以使用N1QL执行任何修改。
UPDATE Blog
SET comments = ARRAY_APPEND( comments, { "comment":"sugar", "user_id":14 } )
WHERE blog = "Coffee";