Skip to main content

Read documents

ArangoDB's official AQL docs for RETURN can be found here

Read a single document

  1. Read a single document from the airport Document collection:
    return DOCUMENT('airports/SFO')
  2. You should see the following response
    [
    {
    "_key": "SFO",
    "_id": "airports/SFO",
    "_rev": "_gdnKCie--U",
    "name": "San Francisco International",
    "city": "San Francisco",
    "state": "CA",
    "country": "USA",
    "lat": 37.61900194,
    "long": -122.3748433,
    "vip": true
    }
    ]

Read a multiple documents

  1. Read a multiple documents from the airport Document collection:
    return DOCUMENT('airports',['SFO','OAK','JFK'])
  2. You should see the following response
    [
    [
    {
    "_key": "SFO",
    "_id": "airports/SFO",
    "_rev": "_gdnKCie--U",
    "name": "San Francisco International",
    "city": "San Francisco",
    "state": "CA",
    "country": "USA",
    "lat": 37.61900194,
    "long": -122.3748433,
    "vip": true
    },
    {
    "_key": "OAK",
    "_id": "airports/OAK",
    "_rev": "_gdnKCiK--s",
    "name": "Metropolitan Oakland International",
    "city": "Oakland",
    "state": "CA",
    "country": "USA",
    "lat": 37.72129083,
    "long": -122.2207167,
    "vip": false
    },
    {
    "_key": "JFK",
    "_id": "airports/JFK",
    "_rev": "_gdnKChu-_X",
    "name": "John F Kennedy Intl",
    "city": "New York",
    "state": "NY",
    "country": "USA",
    "lat": 40.63975111,
    "long": -73.77892556,
    "vip": true
    }
    ]
    ]
  3. The documents dont necessarily need to be from the same collection (though they need to be from the same database).
    • You can specify the id of the document instead of the key
      return DOCUMENT(['scratch/foo-bar','airports/SFO','flights/306630525'])
  4. You should see the following response:
    [
    [
    {
    "_key": "foo-bar",
    "_id": "scratch/foo-bar",
    "_rev": "_gdofeje--A",
    "field1": "foo",
    "field2": "bar"
    },
    {
    "_key": "SFO",
    "_id": "airports/SFO",
    "_rev": "_gdnKCie--U",
    "name": "San Francisco International",
    "city": "San Francisco",
    "state": "CA",
    "country": "USA",
    "lat": 37.61900194,
    "long": -122.3748433,
    "vip": true
    },
    {
    "_key": "306630525",
    "_id": "flights/306630525",
    "_from": "airports/EWR",
    "_to": "airports/MIA",
    "_rev": "_gdqXrU---H",
    "Year": 2008,
    "Month": 1,
    "Day": 11,
    "DayOfWeek": 5,
    "DepTime": 1952,
    "ArrTime": 2259,
    "DepTimeUTC": "2008-01-12T00:52:00.000Z",
    "ArrTimeUTC": "2008-01-12T03:59:00.000Z",
    "UniqueCarrier": "CO",
    "FlightNum": 638,
    "TailNum": "N38727",
    "Distance": 1086
    }
    ]
    ]

Returning customized values

  1. You can return specific values form a document, and reshape the data uncluding the keys and values.
    let airport = DOCUMENT('airports/DEN')
    return {'name':airport.name,'lat':airport.lat,'long':airport.long,'comment':'Third busiest airport in the world'}
  2. You should see the following output:
    [
    {
    "name": "Denver Intl",
    "lat": 39.85840806,
    "long": -104.6670019,
    "comment": "Third busiest airport in the world"
    }
    ]
 
Help us improve

Anything unclear or buggy in this tutorial? Provide Feedback