由于异步,我需要在节点中的数组上执行该函数。我在哪里添加回调以使它返回并继续执行其余数组?
async.eachSeries(processedStockData,(each,callback)=>{
sync.findOne({sku:each.Id}).exec((err,data)=>{
if(err){
return callback(err);
}
if(data){
console.log(data);
if(data.sku===each.Id){
if(data.Stock!= each.Stock || data.Price!=each.Price){
toBeUpdated.push(each);
callback();
}
}
}
});
},(err, data)=>{
console.log(toBeUpdated.length);
});
});
This function only executes once it should be executed for the entire collection.