rethinkdb update query with nested array of objects

627 views Asked by At

Below is the structure I've been working. Criteria is something like I want to update status of nodeName present in Node2 in a single query.

"nodeList": [
  {
    "nodeName": "Node1",
    "status": "Not Ready"
  },
  {
    "nodeName": "Node2",
    "status": "Ready"
  },
  {
    "nodeName": "Node3",
    "status": "Ready"
  }
]

Appreciate your help!!

1

There are 1 answers

0
Govind Jha On

Try this query:-

r.db("your_database").table("your_table_name")
.get('id')
.update({    
          nodeList: r.row('nodeList').map(function (newStatus) {
          return r.branch(
          newStatus('nodeName').eq('field_value'),                                          
          newStatus.merge({status: 'new value'}),newStatus)
        })

});