Search code examples
couchbasesql++

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


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


Solution

  • 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