我正在尝试对来自this answer的查询进行修改。我希望能够进一步过滤顶点,这样我就可以自定义前十名(让它成为特定年份中具有最多角色的十大演员或类似的东西)。
如果我尝试使用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不同),我认为问题可能就是这样,所以我尝试使用路径:TRAVERSAL:false选项。 不幸的是它给出了同样的错误:
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
有人可以解释我收到此错误的原因吗?
答案 0 :(得分: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()