首页 文章

如何在AQL中使用NEIGHBORS?

提问于
浏览
1

我似乎在the cookbook "Using Edge Collections"中描述的NEIGHBORS中重现行为 .

插入数据并运行后:

FOR b IN books RETURN { book: b, authors: NEIGHBORS(books, written, b._id, 'inbound') }
[
  {
    "book" : {
      "_id" : "books/10519631898915",
      "_key" : "10519631898915",
      "_rev" : "10519631898915",
      "title" : "The beauty of JOINS"
    },
    "authors" : [ ]
  }
]

空作者名单!我尝试了这个:

FOR b IN books RETURN { book: b, authors: NEIGHBORS(authors, written, b._id, 'inbound') }
[
  {
    "book" : {
      "_id" : "books/10519631898915",
      "_key" : "10519631898915",
      "_rev" : "10519631898915",
      "title" : "The beauty of JOINS"
    },
    "authors" : [
      "authors/10519474612515",
      "authors/10519475792163"
    ]
  }
]

返回_id列表 . 这些都没有返回我需要的食谱,这是预期的边缘/顶点结构 . (所有已在2.6.9中测试过)

如何使用NEIGHBORS,如何实现我在纯AQL中的目标?是否有一个标准的NEIGHBORS(以及其他图形AQL特性)文档,其中包含每个参数的描述和类型以及返回值?

3 回答

  • 1

    您是否尝试过NEIGHBORS的 includeData 选项?

    FOR b IN books RETURN { book: b, authors: NEIGHBORS(authors, written, b._id, 'inbound', [], {includeData: true}) }
    

    这在我的测试中起作用 . 在大型数据集上,PATHS会更加高效(PATHS计算更多不相关的信息)

    注意:空数组 [] 用于定义仅应遵循的边 . 使用空数组我们遵循所有边,但您也可以遵循特殊边f.e. {label: "written"} 而不是 [] .

  • 1

    是的,我找到了一个解决方案:

    FOR p IN PATHS(books, written, 'inbound') 
    RETURN p.destination
    

    结果:

    Warnings:
    
    [1577], 'collection 'books' used as expression operand'
    
    Result:
    
    [
      {
        "_id": "books/10519631898915",
        "_rev": "10519631898915",
        "_key": "10519631898915",
        "title": "The beauty of JOINS"
      },
      {
        "_id": "authors/10519474612515",
        "_rev": "10519474612515",
        "_key": "10519474612515",
        "name": {
          "first": "John",
          "last": "Doe"
        }
      },
      {
        "_id": "authors/10519475792163",
        "_rev": "10519475792163",
        "_key": "10519475792163",
        "name": {
          "first": "Maxima",
          "last": "Musterfrau"
        }
      }
    ]
    

    它至少得到目标顶点,但它似乎不对,因为我收到警告并且源顶点被包含为目标 . 非常欢迎进一步的阐述和建议 .

  • 1

    更新(2017年):AQL 3.x不再支持NEIGHBORS

    代替

    NEIGHBORS(books, written, b._id, 'inbound')
    

    你可以写一个子查询:

    (FOR v IN 1..1 INBOUND b written RETURN v)
    

相关问题