我正在尝试使用的示例文档是:
{
"name": "level1",
"childLevel1": [
{
"name": "level2",
"childLevel2": [
{
"name": "level3",
"childLevel3": [
{
"name": "level4",
"attribute1": "data"
}
]
}
]
}
]
}
我们想要做的是,使用n1ql向“childLevel3”添加一个数组元素。我尝试过对https://developer.couchbase.com/documentation/server/4.5/n1ql/n1ql-language-reference/update.html
的引用我能够为childLevel2添加一个常规属性,但之后它无法正常工作。这是我一直在尝试的查询。
Update sample
set child2.childLevel3 = ARRAY_PUT(child2.childLevel3, {'attribute' : 'data2'})
FOR child2 in child1.childLevel2 when child2.name == "level3" END
for child1 in childLevel1 when childLevel1.name == 'level2' END
WHERE name == 'level1'
但它给我解析错误,我尝试了其他方法,但没有任何作用。
答案 0 :(得分:1)
尝试
UPDATE sample
SET child2.childLevel3 = ARRAY_PUT(child2.childLevel3, {'attribute' : 'data2'})
FOR child2 in child1.childLevel2
FOR child1 in childLevel1
WHEN childLevel1.name == 'level2' AND child2.name == "level3"
END
WHERE name == 'level1';