ArangoDB - 如何从AQL TRAVERSAL只返回_id?

时间:2015-08-25 14:46:06

标签: arangodb aql

我想仅从_id下方的边和顶点返回p.path

LET from = (
    FOR u IN products
        FILTER u.name == 'pagfr21'
        RETURN u._id
)
FOR p IN TRAVERSAL(products, productsrelated, from[0], 'outbound',
        {minDepth: 0, maxDepth: 3, paths: true})
    RETURN p.path

1 个答案:

答案 0 :(得分:1)

您可以收集p.pathvertices子属性的ID,而不是返回edges,而是将它们分成两个独立的数组,例如。

LET from = (FOR u IN products FILTER u.name == 'foo' RETURN u._id) 

FOR p IN TRAVERSAL(products, productsrelated, from[0], 'outbound', {
  minDepth: 0, 
  maxDepth: 3, 
  paths: true 
}) 

RETURN { 
  vertices: p.path.vertices[*]._id, 
  edges: p.path.edges[*]._id 
}

它将返回这样的结构:

[
  {
    "vertices": [
      "products/..."
    ],
    "edges": []
  },
  {
    "vertices": [
      "products/...",
      "products/..."
    ],
    "edges": [
      "productsrelated/..."
    ]
  },
  ...
  {
    "vertices": [
      "products/...",
      "products/...",
      "products/..."
    ],
    "edges": [
      "productsrelated/...",
      "productsrelated/..."
    ]
  }
]