Search code examples
arangodbaql

How to delete nested record in Arango DB


I want to delete the latitude and longitude

{
  "property_status": "available",
  "property_address": {
    "latitude": 35.1269874,
    "longitude": 45.34897523
  }
}

Solution

  • As you didn't provide any context, let me show you how to do this in AQL:

    FOR doc IN coll
      FILTER ... // find the right document(s)
      UPDATE MERGE(doc, { property_address: {} }) IN coll
    

    The idea of the query is to replace the attribute value of property_address with an empty object. If that object contained additional sub-attributes apart from latitude and longitude that you want to keep, then this is not an option.

    Let's assume the following document:

    {
      "_key": "1234",
      "property_status": "available",
      "property_address": {
        "latitude": 35.1269874,
        "longitude": 45.34897523,
        "place": "Kalar"
      }
    }
    

    If we want to remove latitude and longitude, but not place, then you can do the following in AQL:

    FOR doc IN coll
      FILTER doc._key == "1234"
      UPDATE MERGE(doc, { 
        property_address: UNSET(doc.property_address, "latitude", "longitude")
      }) IN coll