How to update a specific field in all the documents of a bucket using Couchbase UI

Viewed 25

I have a bucket in couchbase which has many documents for example

{
  "id":"1",
  "isAvailable": false
},
{
  "id":"2",
  "isAvailable": false
},
{
  "id":"3",
  "isAvailable": true
},
{
  "id":"4"
}

Now I want to iterate through all the document in this bucket and check if this document has isAvailable: false. If yes then I need to update that document's isAvailable: true.

All this I want to do is from the couchbase UI enter image description here

2 Answers

I think an UPDATE statement would work for you.

Something like:

UPDATE mybucket SET isAvailable = true

"check if this document has isAvailable: false" I don't think you don't need to check if isAvailable is false, since you're just setting all of the isAvailable to true.

If you want to just verify that isAvailable is actually in the document (no matter what its value is), you can do something like this:

UPDATE mybucket
SET isAvailable = true
WHERE isAvailable IS NOT MISSING

Index Selection is based on WHERE clause and mutation of the document is controlled by WHERE clause. If no WHERE clause all the documents are mutated. Mutations full document update and expensive. Do mutation when needed by supply the where clause (If you repeat the statement due to CAS error will not update all of them again)

CREATE INDEX ix1 ON mybucket(isAvailable);

UPDATE mybucket AS b
SET b.isAvailable = true
WHERE b.isAvailable = false;
Related