[英]Return statement not working with User defined functions in Arangodb? How to write an AQl query inside a function?
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"))
)
}
);
引發以下異常
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'
使用aql
模板字符串處理程序來組合查詢,這樣的事情應該讓你開始:
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();
}
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.