问题
Following is the sample document (userdetails) in couchbase.
{ "friends":[
{
"company":"microsoft",
"firstname":"criss",
"lastname":"angel"
},
{
"company":"google",
"firstname":"captain",
"lastname":null
} ] }
based on the company name, i want to remove the respective json document from the array.
n1ql query
update default use keys "userdetails" set friends=array_remove(friends,a) for a in friends when a.company="google" end returning friends
Im not able to remove the json data using the above query.
This query works properly, if we have empty string ( "lastname" : " ") rather than null value.
So, how to remove, if any of the parameter value is "null"
回答1:
You can replace the whole friends array as follows:
UPDATE default
USE KEYS "userdetails"
SET friends = ARRAY a FOR a IN friends WHEN a.company <> "google" END
RETURNING friends;
来源:https://stackoverflow.com/questions/37181435/n1ql-query-to-remove-data-from-array-which-has-parameter-value-null