Update multiple documents in a single query

I want to do an update of multiple documents (50 - 100 or more) in a single query. I have the document id of each doc so I was trying to create multiple SET statements as follows:

UPDATE default SET year.week10.results[0] = { ‘missing’: true, ‘tries’: 4} WHERE meta().id = ‘barnie123’,
year.week10.results[0] = { ‘missing’: false, ‘tries’: 8} WHERE meta().id = ‘fred987’

I get this error:
[ { “code”: 3000, “msg”: “syntax error - at ,”,

note the single version works fine:
UPDATE default SET year.week10.results[0] = { ‘missing’: true, ‘tries’: 4} WHERE meta().id = ‘barnie123’

Checkout the UPDATE syntax at https://developer.couchbase.com/documentation/server/current/n1ql/n1ql-language-reference/update.html

If you want to do conditional update based on document different value you can use as follows.

UPDATE default USE KEYS ["barnie123", "fred987"]
               SET year.week10.results[0] = CASE META().id WHEN "barnie123" THEN { "missing": true, "tries": 4}
                                                           WHEN "fred987" THEN {"missing": true, "tries": 8}
                                                                          ELSE year.week10.results[0] END;
1 Like