I want to calculate the indegree and outdegree of a node in a graph given the vertex and the edge collection. Below is the code that I have written. UDF function code:
require("@arangodb/aql/functions").register(
"MYFUNCTIONS::VERTEX::INDEGREE",
function(vertex,edge, node) {
"use strict";
let db = require('@arangodb').db;
let aql = require('@arangodb').aql;
let query = aql` for t in ${edge} filter t._to == ${node} COLLECT WITH COUNT INTO length return length`;
return db._query(query).toArray();
}
);
When I call the function like below I am getting an error as "AQL: collection or array expected as operand to FOR loop; you specified type 'string' with content '"Transaction"' (while optimizing ast)"
UDF Function calling code: db._query('return MYFUNCTIONS::VERTEX::INDEGREE("Account", "Transaction", "Account/123")');
where Account is a Document Collection, Transaction is an Edge Collection and Account/123 is a node in the graph.