tldr; ArangoDB supports indexed nested object arrays, but without some planning and profiling, it may not use your indices.
Document Databases are great, but querying nested object arrays always adds some complexity. In DynamoDB, it is basically impossible without doing a full scan or flattening the data structure. ElasticSearch has good support for nested documents or indexes keys.
ArangoDB supports arrays of nested objects similarly to ElasticSearch. ArangoDB has an excellent profiler, making it simple to examine query execution. After some experimenting, I was able to optimize queries of arrays of nested objects.
Sample Data:
{
"name": "Parent 1",
"children": [
{
"name": "Child 1",
"type": "Nested Child",
"key": "1234"
}
]
}
Test Index
Index:
type: persistent
unique: true
fields: children[*].key, children[*].type
Query 1:
This is a sample query that filters by the nested object. This will NOT use the index.
FOR t IN testCollection
FOR tc IN t.children
FILTER tc.type == 'Nested Child'
AND tc.key == '1234'
LIMIT 1
RETURN { name: t.name, childName: tc.name }
Query 2:
This is a variation of the same query. This WILL use the index.
FOR t IN testCollection
FOR tc IN t.children
FILTER 'Nested Child' IN t.children[*].type
AND '1234' IN t.children[*].key
AND tc.type == 'Nested Child'
AND tc.key == '1234'
LIMIT 1
RETURN { name: t.name, childName: tc.name }
Note: if you want to return the specific child object, you need to join the child entity and you need to filter on the indexed child values – you double the filters. In effect, this finds the document based on the index, then scans through each of the child objects to find the match. The double filters are only required if you are concerned about returning the specific child object.
Results:
While Query 1 seems more natural, with a real dataset, a similar query took 5 s. Query 2 on the same dataset took 30 ms.
Conclusion:
ArangoDB supports indexed nested object arrays, but without some planning and profiling, it may not use your indices.
Especially when learning a new database like ArangoDB, use the Profiling tools and ensure that the execution plan meets your expectations.
Thanks for reading! I'd love to hear your thoughts or questions.