如何在ArangoDB中以编程方式在集合内创建边?

问题描述 投票:0回答:1

假设我正在创建一个用于存储家谱的集合(仅父级关系很重要)。我有一个名为people的顶点集合和一个名为edges的边集合。

人员集合中的文档如下:

{"name" : "xyz", "age": 12, "uniqueid": 10011, "parent_uniqueid": 9808}

[使用edgesuniqueid属性,通过AQL填充parent_uniqueid集合的最佳方法是什么。

graph-databases arangodb
1个回答
0
投票

下面的查询假定对于people中的每个节点p,

  1. p._id = p.uniqueid
  2. 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

检查INSERThttps://www.arangodb.com/docs/stable/aql/operations-insert.html#setting-query-options子句的选项,看是否有任何一种适用于您的情况。

© www.soinside.com 2019 - 2024. All rights reserved.