[英]Is there a way to get the same output on a foxxservice as on the arangosh?
The goal is to develop a foxxservice
that simply delivers the available user collections in json
. 目标是开发一个
foxxservice
,它可以简单地在json
传递可用的用户集合。
What I've already tried: Set up local arangodb
server. 我已经尝试过的方法:设置本地
arangodb
服务器。 Then read the documentation and use the arangosh
to try the commands. 然后阅读文档并使用
arangosh
尝试命令。 Then extended the foxxservice
hello world example to get the same output. 然后扩展
foxxservice
hello world示例以获取相同的输出。
arangosh
127.0.0.1:8529@TestDatabase> db._collections()
[
[ArangoCollection 2393976, "_appbundles" (type document, status loaded)],
[ArangoCollection 2393973, "_apps" (type document, status loaded)],
[ArangoCollection 2393961, "_aqlfunctions" (type document, status unloaded)],
[ArangoCollection 2394097, "_fishbowl" (type document, status loaded)],
[ArangoCollection 2393964, "_frontend" (type document, status loaded)],
[ArangoCollection 2393943, "_graphs" (type document, status loaded)],
[ArangoCollection 2393970, "_jobs" (type document, status loaded)],
[ArangoCollection 2393948, "_modules" (type document, status loaded)],
[ArangoCollection 2393967, "_queues" (type document, status loaded)],
[ArangoCollection 2393951, "_routing" (type document, status loaded)],
[ArangoCollection 2394131, "Relation" (type edge, status loaded)],
[ArangoCollection 2394114, "Table" (type document, status loaded)]
]
The foxxservice: foxxservice:
'use strict';
const createRouter = require('@arangodb/foxx/router');
const db = require('@arangodb').db;
const router = createRouter();
module.context.use(router);
router.get('/hello-world', function (req, res) {
res.send('Hello World!');
const collections = db._collections();
res.json(collections);
})
.response(['application/json'], 'A generic greeting.')
.summary('Generic greeting')
.description('Prints a generic greeting.');
Actually, I was expecting the same json. 实际上,我期望使用相同的json。 Hopefully it is not impossible for safety reasons.
希望出于安全原因并非不可能。
But this is what the browser shows: 但这是浏览器显示的内容:
[
{"_id":"2393976","_dbName":"TestDatabase"},
{"_id":"2393973","_dbName":"TestDatabase"},
{"_id":"2393961","_dbName":"TestDatabase"},
{"_id":"2394097","_dbName":"TestDatabase"},
{"_id":"2393964","_dbName":"TestDatabase"},
{"_id":"2393943","_dbName":"TestDatabase"},
{"_id":"2393970","_dbName":"TestDatabase"},
{"_id":"2393948","_dbName":"TestDatabase"},
{"_id":"2393967","_dbName":"TestDatabase"},
{"_id":"2393951","_dbName":"TestDatabase"},
{"_id":"2394131","_dbName":"TestDatabase"},
{"_id":"2394114","_dbName":"TestDatabase"}
]
Possible solution: 可能的解决方案:
'use strict';
const createRouter = require('@arangodb/foxx/router');
const db = require('@arangodb').db;
const router = createRouter();
module.context.use(router);
router.get('/hello-world', function (req, res) {
res.send('Hello World!');
var collections = [];
db._collections().forEach(function(element) {
if(!element.name().startsWith("_")) {
var obj = {};
obj[element._id] = element.name();
collections.push(obj);
}
});
res.json(collections);
})
.response(['application/json'], 'A generic greeting.')
.summary('Generic greeting')
.description('Prints a generic greeting.');
The generated output: 生成的输出:
[
{"2394131":"Relation"},
{"2394114":"Table"}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.