I am new to N1QL, I want to delete matching string from array.
Here is my required array called inspection:
"job_1": {
"inspection": ['11','22','33','44'] //This is Array
},
"job_2": {
"inspection": ['22','33','44'] //This is Array
},
"job_3": {
"inspection": ['11','22'] //This is Array
}
i want to delete '22' from all 3 array located inside each job (it may be possible that value which i wants to delete is not present in inspection array):
How do i delete that using delete query, Can any one help me to get query ?
Thank you in advance!
Use WHERE clause to update the document that has required value. After that use ARRAY construct to form new ARRAY and assign it. You can also use ARRAY functions.
UPDATE default AS d
SET d.inspection = ARRAY v FOR v IN d.inspection WHEN v != "22" END
WHERE "22" IN d.inspection;
OR
UPDATE default AS d
SET d.inspection = ARRAY v FOR v IN d.inspection WHEN v != "22" END
WHERE ANY v IN d.inspection SATISFIES v = "22" END;
Reference
https://blog.couchbase.com/working-json-arrays-n1ql/ https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/indexing-arrays.html https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/update.html https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/arrayfun.html