所以这里我有一个数组,我想遍历它并将其中的每个对象保存在mongo
中,但是当我这样做时,什么都不会发生,因为猫鼬async
模块所以我想用async
库解决这个问题,我如何使用这个库来解决这个问题这是我的节点JS代码:
for(var index in sample){
var temp = new db.collection_Name(sample[index]);
temp.save()
}
使用异步模块,它看起来像这样:
var async = require('async');
async.each(samples, function(sample, next) {
var temp = new db.collection_name(sample);
temp.save(function(err, doc) {
next();
});
}, function() {
console.log('all done!');
});