【问题标题】:How can I create edges within a collection programmatically in ArangoDB?如何在 ArangoDB 中以编程方式在集合中创建边?
【发布时间】:2019-09-30 11:15:48
【问题描述】:

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

人员集合中的文档如下所示:

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

使用uniqueidparent_uniqueid 属性通过AQL 填充edges 集合的最佳方法是什么。

【问题讨论】:

    标签: graph-databases arangodb


    【解决方案1】:

    下面的查询假设对于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
    

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

    【讨论】:

      猜你喜欢
      • 2020-03-23
      • 1970-01-01
      • 2020-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多