假设我正在创建一个用于存储家谱的集合(仅父级关系很重要)。我有一个名为people
的顶点集合和一个名为edges
的边集合。
人员集合中的文档如下:
{"name" : "xyz", "age": 12, "uniqueid": 10011, "parent_uniqueid": 9808}
[使用edges
和uniqueid
属性通过AQL填充parent_uniqueid
集合的最佳方法是什么。
下面的查询假定对于people
中的每个节点p,
p._id = p.uniqueid
,p.parent_uniqueid = (parent of p)._id
(如果p有父母)。FOR p in people
FILTER HAS(p, 'parent_uniqueid')
LET edges = (
FOR e in edges
FILTER e._from == p.parent_uniqueid and e._to == p._id
RETURN 1
)
FILTER LENGTH(edges) == 0
INSERT {_from: p.parent_uniqueid, _to: p._id} into edges
在INSERT
处检查https://www.arangodb.com/docs/stable/aql/operations-insert.html#setting-query-options子句的选项,看是否有任何一种适用于您的情况。