yasuro
yasuro

Reputation: 23

How UNSET nested attribute?

I have such document:

{
  "name": "FirstObj",
  "attributes": {
    "my_attributes/601890": {
      "value": "Hellow World",
      "id": "my_attributes/601890",
      "name": "TEstAttr",
      "myAttribute": "my_attributes/601890",
      "_class": "MyAttributeValue"
    }
  },
  "_class": "MyObj"
}

I cannot write AQL query which unsets "myAttribute": "my_attributes/601890". So i want to get such final document:

  {
  "name": "FirstObj",
  "attributes": {
    "my_attributes/601890": {
      "value": "Hellow World",
      "id": "my_attributes/601890",
      "name": "TEstAttr",
      "_class": "MyAttributeValue"
    }
  },
  "_class": "MyObj"
}

Note, field attributes is object like key-value.(my_attributes/601890: {}) The field will be huge in the future

Upvotes: 1

Views: 325

Answers (1)

darkheir
darkheir

Reputation: 8950

You can try to set the value to null and set the options keepNull to false to remove the field during the update.

For item in collection
    UPDATE item 
    WITH {attributes: {"my_attributes/601890": {myAttribute: null}} } 
    IN collection 
    OPTIONS { keepNull: false }

Upvotes: 1

Related Questions