nested - 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
比较属性 - 它不关心属性的类型,因此如果您尝试匹配嵌套对象,它们必须具有相同的属性/值;因此,您不能将任意深度的结构覆盖并检查其对应关系。
在给定的示例中,您可以选择子结构LET
并使用MATCHES
它
LET doc = { "a" : { "c" : 1, "b" : 1 }}
LET a = doc.a
RETURN MATCHES(
a,
{ "c": 1}
)
要利用 arangojs 功能使用路径来窥视结构,您可以编写一个使用示例查询的用户函数并从 AQL 调用它(https://www.arangodb.com/docs/stable/aql/extending.html)。
注意事项:您的语言的 arangodb 客户端库应该提供对注册用户函数的方便访问(例如class AqlUserFunctions
in arangodb-php
)。
推荐阅读
- pandas - 对多级索引进行排序
- excel - Excel - 查找范围内与上一行不同的所有值
- pixi.js - 为什么 mousemove 事件会在 PIXI JS 的精灵区域之外执行?
- sql - 如何使用 SQL 显示不重复的数据
- java - 如何在Java中颠倒堆栈和队列的顺序
- javascript - Javascript unicode 正则表达式
- java - Counting a digit from second input
- apache-flink - List all Sources and Sinks in a Flink SQL job
- node.js - Understanding streams in Node js
- java - 在 Java 中使用嵌套循环的 2020 年日历