我目前正在尝试使用async.each更新一个带有订单号的数组,以便它并行运行。但是,似乎数组长度越大,更新失败的次数就越多。如何更新阵列中的每个订单号,而不考虑阵列中的阵列长度
下面是我的javascript代码:
axios.post(`/api/admin/add-into-batch`, {orders})
.then(function(data){
location.reload();
})
router.post('/admin/add-into-batch', function (req, res, next) {
// req.body.orders = [1,2,3,4,..,120]
async.each(req.body.orders, function(order, cb){
CurrentOrder.findByIdAndUpdate(order._id, order, function(err, data){
if (err) return next(err)
cb()
})
}, function(err) {
// if any of the update produced an error, err would equal that error
if( err ) {
// One of the iterations produced an error.
// All processing will now stop.
next(err)
} else {
return res.sendStatus(200);
}
})
})