Right syntax of Update

Hi,

I have a document in Couchbase as structured below. I want to update the value for field body. Please help me with the right syntax.

Current doc

{
“body”: [
“11”,
“WAKIRFALL”,
“3P-W6-MO”
],
“desx”:“ddd”
}

Future State - The below query shows sybtax error

UPDATE business_rules set body=’[“11”,“SAEDED”,“3P-U6-MO”]’ using keys [‘rule_external_rt_1’]

Thanks. Please help

UPDATE business_rules AS br USE KEYS ["rule_external_rt_1"]
SET br.body =  ARRAY_REPLACE(br.body, "WAKIRFALL", "SAEDED");

https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/update.html

https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/arrayfun.html#fn-array-replace

Hi,

Thanks for the pointers. Is there any function to replace an array value based on position,. E.g.

I want to replace the value of 5th element of array as “xx”.

ARRAY_REPLACE(br.body,5,“xx”)

UPDATE business_rules AS br USE KEYS ["rule_external_rt_1"]
SET br.body[4] =  "xxx";


 UPDATE business_rules AS br USE KEYS ["rule_external_rt_1"]
 SET b.body = ARRAY  (CASE WHEN pos == 4 THEN "xx" ELSE v END) FOR pos:v IN body END

Thank you so much :slight_smile: