4

我正在尝试对此答案的查询进行变体。我希望对顶点进行进一步过滤,以便我可以自定义前十名(使其成为给定年份或类似情况下角色最多的前十名演员)。

如果我尝试使用 NEIGHBORS 函数,则会收到以下错误:

arangosh [_system]> db._createStatement({query: 'FOR vert IN imdb_vertices FILTER vert.type == "Person" LET edge_count = (LENGTH(NEIGHBORS(imdb_vertices, imdb_edges, vert, "outbound", [{"type": "Role", "$label": "ACTS_IN"}]))) SORT edge_count DESC LIMIT 10 RETURN {"name": vert.name,  "count": edge_count}'}).execute().toArray()
JavaScript exception in file '/usr/share/arangodb/js/client/modules/org/arangodb/arangosh.js' at 101,13: TypeError: TypeError: Object #<ShapedJson> has no method 'indexOf'
!      throw new TypeError(requestResult.errorMessage);
!            ^
stacktrace: TypeError: TypeError: Object #<ShapedJson> has no method 'indexOf'
    at Object.exports.checkRequestResult (/usr/share/arangodb/js/client/modules/org/arangodb/arangosh.js:101:13)
    at ArangoStatement.execute (/usr/share/arangodb/js/client/modules/org/arangodb/arango-statement.js:171:12)
    at (shell):1:290

由于 NEIGHBORS 似乎同时返回边和顶点(与返回边的 EDGES 不同),我认为问题可能是这样,所以我尝试使用 paths: false 选项使用 TRAVERSAL。不幸的是,它给出了同样的错误:

db._createStatement({query: 'FOR vert IN imdb_vertices FILTER vert.type == "Person" LET edge_count = (LENGTH(TRAVERSAL(imdb_vertices,imdb_edges, vert, "outbound", {paths: false, followEdges: [{"type": "Role", "$label": "ACTS_IN"}]}))) SORT edge_count DESC LIMIT 10 RETURN {"name": vert.name,  "count": edge_count}'}).execute().toArray()
JavaScript exception in file '/usr/share/arangodb/js/client/modules/org/arangodb/arangosh.js' at 101,13: TypeError: TypeError: Object #<ShapedJson> has no method 'indexOf'
!      throw new TypeError(requestResult.errorMessage);
!            ^
stacktrace: TypeError: TypeError: Object #<ShapedJson> has no method 'indexOf'
    at Object.exports.checkRequestResult (/usr/share/arangodb/js/client/modules/org/arangodb/arangosh.js:101:13)
    at ArangoStatement.execute (/usr/share/arangodb/js/client/modules/org/arangodb/arango-statement.js:171:12)
    at (shell):1:318

有人可以解释为什么我会收到此错误吗?

4

1 回答 1

5

我认为问题在于上述查询中的vert是一个顶点对象,但它应该是一个顶点_id(或顶点_key)。这就是发生异常的原因。

第一个查询可以修改如下:

db._createStatement({query: 'FOR vert IN imdb_vertices FILTER vert.type == "Person" LET edge_count = (LENGTH(NEIGHBORS(imdb_vertices, imdb_edges, vert._id, "outbound", [{"type": "Role", "$label": "ACTS_IN"}]))) SORT edge_count DESC LIMIT 10 RETURN {"name": vert.name,  "count": edge_count}'}).execute().toArray()
于 2014-05-05T19:39:11.593 回答