0

目标是开发一个foxxservice简单地以json.

我已经尝试过:设置本地arangodb服务器。然后阅读文档并使用arangosh来尝试命令。然后扩展foxxservicehello 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)] 

]

狐狸服务:

'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.');

实际上,我期待相同的 json。希望出于安全原因,这不是不可能的。

但这就是浏览器显示的内容:

[
{"_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"}
]
4

1 回答 1

0

可能的解决方案:

'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.');

生成的输出:

[
    {"2394131":"Relation"},
    {"2394114":"Table"}
]
于 2019-09-08T18:02:40.547 回答