I want to execute a specific N1QL update query in batches using limit of 5000. The set of docs getting updated in first batch should not be overwritten/overlapped by the second batch and so on .Since order by and offset clause is not allowed in update clause is there any way so that I can update first 5000 docs in first batch, next 5000 in second and so on.
First 5000 is decided based on sorting order of a document Id which is alphanumeric. Second batch should consider next set of 5000 docs
UPDATE default AS d
SET d.c = 10
WHERE d.a > 10 AND d.b > "abc" LIMIT 1000;
Option 1:
Above statement can be written as follows
With scan_consistency request_plus. This allows not to mutate the document again if already mutated.
UPDATE default AS d
SET d.c = 10
WHERE d.a > 10 AND d.b > "abc" AND d.c != 10 LIMIT 1000;
Option 2:
Use select statement and get document keys ( you can use no pagination or pagination or Using OFFSET and Keyset in N1QL | The Couchbase Blog)
Then use SDK to mutate document
Option 3: If you predicates are all equal then you can add META().id > $mid and pass the $mid each execution as described in the link
UPDATE default AS d
SET d.c = 10
WHERE d.a = 10 AND d.b = "abc" AND d.c != 10 AND META(d).id > $mid LIMIT 1000 RETURNING META(d).id ;
Option 4: MERGE statement and control pagination through the source of MERGE