1

I have tried to modify a document by using data queries.

This works fine for a normal structure. But when query is in a array form. This doesn't seems to replace or modify the status. How can I achieve this ?

this is my array

 `{
  "slave_state_datasets": [
    {
    "no": 0,
    "name": "abce",
    "status": true,
    "interrupt_time": 0.2,
    "timestamp": 1,
    "dataset_input": [
      {
      "data": 8,
      "ui16_u_u2": 1,
      "ui16_u_dip_min": 1,
      "ui16_u_swell_max": 1,
       }
    ]
  }
 ]
 }`
cantona_7
  • 852
  • 3
  • 16
  • 30

1 Answers1

1

Tested this on 3.3.3, based on this answer by RienNeVaPlu͢s

for t in test
filter t._key == '516226'
let alteritem = (for s in t.slave_state_datasets
            let updateStatus = MERGE(s, {status: false})
        return updateStatus)
update t with {slave_state_datasets:alteritem} IN test

You assign the inner value to alteritem, update the status with MERGE and then update the parent document. See the linked answer for more detail on filtering arrays.

Andrew Grothe
  • 2,342
  • 1
  • 31
  • 42