Json N1QL:向现有couchbase文档添加新对象
是否可以使用N1QL 例如,我有:Json N1QL:向现有couchbase文档添加新对象,json,couchbase,n1ql,database,nosql,Json,Couchbase,N1ql,Database,Nosql,是否可以使用N1QL 例如,我有: { "blog": "Coffee", "user_id": 41, "comments": [ { "comment": "cup", "user_id": 883 }, { "comment": "water", "user_id": 790 } ] } 我想使用N1QL在注释中添加糖,从而得出以下结果: { “博客”:“咖啡”, “用户id”:41, “
{
"blog": "Coffee",
"user_id": 41,
"comments": [
{
"comment": "cup",
"user_id": 883
},
{
"comment": "water",
"user_id": 790
}
]
}
我想使用N1QL在注释中添加糖,从而得出以下结果:
{
“博客”:“咖啡”,
“用户id”:41,
“评论”:[
{
“评论”:“杯子”,
“用户id”:883
},
{
“评论”:“水”,
“用户id”:790
},
{
“评论”:“糖”,
“用户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 ("}
是的,您可以使用N1QL执行任何修改
UPDATE Blog
SET comments = ARRAY_APPEND( comments, { "comment":"sugar", "user_id":14 } )
WHERE blog = "Coffee";