Không cần tạo phiên bản new hostModel()
tại đây ... sử dụng trực tiếp hostModel
và cũng không cần save()
cũng như vì chèn nhiều chính nó sẽ tạo ra các bộ sưu tập ... và đảm bảo rằng payload.data
có mảng đối tượng
router.post('/host', function (req, res, next) {
const array = [{hostname: 'hostname', timestamp: 'timestamp'},
{hostname: 'hostname', timestamp: 'timestamp'}]
var payload = req.body;
(async function(){
const insertMany = await hostModel.insertMany(array);
console.log(JSON.stringify(insertMany,'','\t'));
res.status(200).send('Ok');
})();
});