[英]How to post an array of json objects in Foxx to arangodb
我正在嘗試使用arangodb在Foxx中創建一個簡單的現有微服務。 我已經按照入門指南進行操作,但是我對javascript還是很陌生,因此我相信這很簡單。
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.');
a)我如何做這個簡單的任務
b)調試腳本的最佳方法是什么
謝謝!
修正了這個非常簡單的概念:
router.post('/create_entries', function (req, res) {
var data = req.body;
for(var i = 0; i < data.length; i++) {
var obj = data[i];
var res = foxxColl.save(obj);
}
})
.body(joi.array().items(joi.object().unknown(true)), ['json'])
//.response(['text/plain'], 'Entries stored in the collection.')
.summary('Store entries')
.description('Stores entries in the "initial_balance" collection.');
我仍然不確定如何在Foxx中進行調試
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.