通过文档查看并想知道是否有办法直接更新数组中的doc。我只找到了Append,Prepend和Insert,现在我的工作是
bucket
.mutateIn(docID)
.remove(path + "[" +index +"]")
.arrayInsert(path +"[" +index +"]", doc)
.execute((err, result) => {}
哪个有效,但我怀疑理想,因为它导致2个操作在我的情况下实际3在文档,因为我必须在数组中找到此Doc的索引之前我可以删除并再次插入
有一个名为sub-document的replace
命令允许更新元素。
bucket
.mutateIn(docID)
.replace(path + "[" +index +"]", doc)
.execute((err, result) => {}
看起来这个方法在SDK中缺失,我会为它打开一张票。在此期间,您还可以通过ARRAY_REMOVE或ARRAY_REPLACE(tks to vsr)使用N1QL
https://docs.couchbase.com/server/6.0/n1ql/n1ql-language-reference/arrayfun.html#fn-array-remove