简体   繁体   中英

ArangoDB - How can I return only the _id from AQL TRAVERSAL?

I want to return only the _id from edges and vertices from the p.path below.

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

Instead of returning p.path you could collect the ids of the vertices and edges subattributes and return them in two separate arrays, eg

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 
}

It will return a structure like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM