1
我想用arangodb在Foxx中创建一个简单的现有微服务。我已经开始了,但是我对JavaScript很新,所以我确信这很简单。如何将Foxx中的json对象数组发布到arangodb
const db = require('@arangodb').db;
const errors = require('@arangodb').errors;
const foxxColl = db._collection('myCollection');
const DOC_NOT_FOUND = errors.ERROR_ARANGO_DOCUMENT_NOT_FOUND.code;
router.post('/create_entry', function (req, res) {
const data = req.body;
const meta = foxxColl.save(req.body);
res.send(Object.assign(data, meta));
})
.body(joi.object().required(), 'Entry to store in the collection.')
.response(joi.object().required(), 'Entry stored in the collection.')
.summary('Store an entry')
.description('Stores an entry in the "initial_balance" collection.');
这显然是好的。我想要加载散装有效载荷
[
{"key1": "value1", "key2": "valueA"},
{"key1": "value2", "key2": "valueB"},
{"key1": "value3", "key2": "valueC"}
]
我有这个失败(内部服务器错误)。
const initSchmea = joi.object().keys({user_id:joi.string().required(),amount: joi.number().required()});
router.post('/initial_balance/bulk', function (req, res) {
var data = req.body.;
for(var i in data)
{
var res = foxxColl.save(d[i]);
}
res.send('Done')
})
.body(joi.array().items(initSchmea.required()), 'Entry to store in the collection.')
.response(['text/plain'], 'Entries stored in the collection.')
.summary('Store entries')
.description('Stores entries in the "initial_balance" collection.');
一)我怎么做这个简单的任务
b)当调试脚本
感谢的最好方式!
我做了我的大部分调试只需使用的console.log,然后在寻找日志菜单项的ArangoDB Web UI。这对于查看大量数据并不好,但通过Object.keys和JSON.stringify,我总是可以找出错误的原因。 –
谢谢,我也发现之后。现在一切都很好;) – RHSMan