0
require("@arangodb/aql/functions").register(
    "MYFUNCTIONS::VERTEX::INDEGREE", 
    function(vertex,edge, node) {
        "use strict"; 
        AQL_Query(
            (return( "for t in Transaction  collect vertex_count=t._from with into n return x"))
        )
    }
);

throws the following exception

JavaScript exception: SyntaxError: Unexpected token 'return'
!require("@arangodb/aql/functions").register("MYFUNCTIONS::VERTEX::INDEGREE", function(vertex,edge, node) {"use strict"; AQL_Query((return( "for t in Transaction  collect vertex_count=t._from with into n return x")))});
!                                                                                                                                   ^^^^^^
stacktrace: SyntaxError: Unexpected token 'return'

1 Answer 1

0

Use the aql template string handler to assamble the query, something like this should get you started:

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 Transaction  
              collect vertex_count=t._from with into n 
              return n
        `;
        return db._query(query).toArray();
    }
);
Sign up to request clarification or add additional context in comments.

3 Comments

Also how to call a function in the Arangoshell?
In AQL-statements; you register functions for use in aql statements...; db._query(aql`return MYFUNCTIONS::VERTEX::INDEGREE()`);. Maybe a foxx-service is what you really want to develop? (though a registered function can be a nice stepping stone).
To call user functions from user functions see this Q/A: stackoverflow.com/questions/28366753/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.