Question

I am trying to do a variation on the query from this answer. I was hoping to do some further filtering the vertices so I could do customize the top ten (make it top ten actors with the most roles for a given year or something similar).

If I try with the NEIGHBORS function I get the following error:

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

Since NEIGHBORS seems to return both edges and vertices (unlike EDGES which returns edges), I figured the problem might be that, so I tried with TRAVERSAL using the paths: false option. Unfortunately it gives the same error:

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

Can someone explain why I am getting this error?

Was it helpful?

Solution

I think the problem is that vert in the above query is a vertex object, but it is expected to be a vertex _id (or vertex _key). This is the reason why the exception occurs.

The first query can be modified as follows:

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()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top