How to update document by adding key-value in Couchbase

Hello,

Suppose I have a document

{“key1”:value1, “key2”:“value2”}

How can I use N1QL to update the document to have another key value pair?

{“key1”:value1, “key2”:“value2”,“key3”:value3}

I have looked at the update set features, but it’s to update key values that are already present.

Thanks!

Simply set the new key-value.

UPDATE bucket SET key3 = "value3" WHERE "key1" = "value1";

UPDATE works in sets like SQL. If you know the document to update, use the USE KEYS clause otherwise, use the WHERE clause carefully.

UPDATE bucket USE KEYS "mykey" SET key3 = "value3" ;

Hi Keshav
I am trying to update all the documents available in one bucket .

I am trying to execute
update bucket tower SET “storeTypes” = [“EXPRESS_DELIVERY”] WHERE “languageIsoCode”: “en”;

But getting error

{
“code”: 3000,
“msg”: “syntax error - at bucket”,
“query”: “update bucket tower SET "storeTypes" = ["EXPRESS_DELIVERY"] WHERE "languageIsoCode": "en"”
}

“bucket” in the example given is intended as the name of your bucket. So if your bucket is “tower” then the statement is:

update tower SET `storeTypes` = ["EXPRESS_DELIVERY"] WHERE `languageIsoCode` = "en";

HTH.