简体   繁体   中英

ARANGODB AQL MATCHES() with nested objects not possible

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

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 (eg class AqlUserFunctions in arangodb-php ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM