如何通过SDK更新couchbase中的数组

问题描述 投票:0回答:2

通过文档查看并想知道是否有办法直接更新数组中的doc。我只找到了Append,Prepend和Insert,现在我的工作是

 bucket
  .mutateIn(docID)
  .remove(path + "[" +index +"]")
  .arrayInsert(path +"[" +index +"]", doc)
  .execute((err, result) => {}

哪个有效,但我怀疑理想,因为它导致2个操作在我的情况下实际3在文档,因为我必须在数组中找到此Doc的索引之前我可以删除并再次插入

couchbase
2个回答
1
投票

有一个名为sub-documentreplace命令允许更新元素。

 bucket
  .mutateIn(docID)
  .replace(path + "[" +index +"]", doc)
  .execute((err, result) => {}

0
投票

看起来这个方法在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

© www.soinside.com 2019 - 2024. All rights reserved.