Retriving document fields only if the document exists?

22 views
Skip to first unread message

Dave Challis

unread,
May 30, 2019, 12:46:55 PM5/30/19
to ArangoDB
Using AQL, is there a good way to get fields from a single document only if it exists?

E.g. say I've got a query like:

LET d = DOCUMENT("myCollection", "123")
RETURN
{ "name": d.name, "age": d.age }


If the document doesn't exist in the collection, this returns:

[
 
{
   
"name": null,
   
"size": null
 
}
]


However, this doesn't distinguish it from the case where the document does exist in the collection, but has both its fields set to null.

Is there a way of changing the above query so that the result is instead either just [] or null if the document isn't found? Or would I need to use two separate queries (one to check existence, then one to fetch the data if it does exist)?
Reply all
Reply to author
Forward
0 new messages