Reputation: 853
I use MATCHES()
AQL function to search for entries in the arango database matching an example. This feature works nice for plain examples, but I cannot get it work properly with the nested features. See example:
RETURN MATCHES(
{ "a" : { "c" : 1 }, "b" : 1 },
{ "a" : { "c" : 1 } },
false
)
This returns true
, however if I try:
RETURN MATCHES(
{ "a" : { "c" : 1, "b" : 1 }},
{ "a" : { "c" : 1 } },
false
)
It returns false
!! (I expected to return true)
I have read that this is known in the Query by example
section
https://www.arangodb.com/docs/stable/data-modeling-documents-document-methods.html#query-by-example
Their solution is to use dot notation, but it does not work in AQL
Following their example:
RETURN MATCHES(
{ "a" : { "c" : 1, "b" : 1 } },
{ "a.c" : 1 },
false
)
returns false
(and I would expect to return true)
How can I then, use the MATCHES()
for nested attributes?
FYI: I use arangodb v3.5.5-1
Clarification:
I want to get a match of { "a" : { "c" : 1, "b" : 1 } }
by giving { "a" : { "c" : 1 } }
as example
I've posted the Issue in ArangoDB repository: https://github.com/arangodb/arangodb/issues/12541
Upvotes: 1
Views: 523
Reputation:
MATCHES
compares attributes - it doesn't care what type the attributes have, so if you are trying to match nested objects, they have to have the same attributes/values; it follows that you can not have arbitrarily deep structures overlayed and checked for correspondence.
In the given example you can pick out the substructure with LET
and use MATCHES
against that
LET doc = { "a" : { "c" : 1, "b" : 1 }}
LET a = doc.a
RETURN MATCHES(
a,
{ "c": 1}
)
To leverage the arangojs capability to use paths to peek into the structure, you can write a user function that uses query by example and call that from AQL (https://www.arangodb.com/docs/stable/aql/extending.html).
Nota Bene: The arangodb client library of your language should provide convenient access to registering user functions (e.g. class AqlUserFunctions
in arangodb-php
).
Upvotes: 0