Update a subobject in a JSON object

Hi all,

I have a huge JSON object (document) stored in couchbase .
eg.
{‘a’: 23,
‘b’: 73
‘c’: [[23,34], [23, 67]],
‘d’: {
‘abc’: 34,
}
}

I just want to update value for ‘c’ to something like: ‘c’: [[23,34], [23, 67], [89,56]].
How can I do this?
Do I need to load entire document to do such an operation?

Thank you.

If use N1QL UPDATE statement it will fetch whole document and update whole document. SDK’s provide subdoc API (https://docs.couchbase.com/server/5.1/developer-guide/sub-doc-api.html ) to update specific path and you can explore Mutating Array Fields.

N1QL Update statement looks as follows.

UPDATE default AS d
SET d.c = ARRAY_APPEND(d.c, [89,56])
WHERE …;

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

Thanks you very much :slight_smile:
I will try this and will come back.