Search code examples
sqlcouchbasesql++

N1QL Couchbase update properties on nested object where key is dynamic


How to update all properties active to false if key of object is a number:

 {
  "id": 1,
  "items": {
    "2": {
      "id": 2,
      "active": true
    },
    "3": {
      "id": 3,
      "active": true
    },
    "5": {
      "id": 5,
      "active": true
    }
  },
  "status": true
}

Solution

  • UPDATE default AS d
    SET d.items.[v].active = false 
        FOR v IN OBJECT_NAMES(d.items) END
    WHERE .....