2

以下是 couchbase 中的示例文档(userdetails)。

{  "friends":[  
  {  
     "company":"microsoft",
     "firstname":"criss",
     "lastname":"angel"
  },
  {  
     "company":"google",
     "firstname":"captain",
     "lastname":null
  }  ] }

根据公司名称,我想从数组中删除相应的 json 文档。

n1ql 查询

update default use keys "userdetails" set friends=array_remove(friends,a) for a in friends when a.company="google" end returning friends

我无法使用上述查询删除 json 数据。

如果我们有空字符串 ( "lastname" : " " ) 而不是 null 值,则此查询可以正常工作。

那么,如果任何参数值为“null” ,如何删除

4

1 回答 1

3

您可以按如下方式替换整个朋友数组:

UPDATE default
USE KEYS "userdetails"
SET friends = ARRAY a FOR a IN friends WHEN a.company <> "google" END
RETURNING friends;
于 2016-05-12T15:49:17.363 回答