猫鼬模型不会保存在async.forEach循环中

时间:2020-03-21 17:59:11

标签: node.js asynchronous mongoose

我正在创建一些代码以上传excel数据并发送回HTTP响应。读取excel文件后,我然后遍历数组,并为每个项目创建一个Mongoose对象并填充字段,然后使用.save()保存对象 在猫鼬保存操作完成之前完成async.forEach循环 我正在使用async.forEach遍历整个数组-虽然它遍历Array中的所有项目都不会保存它们,并且不会产生任何错误来帮助我识别出什么问题

async.each(
  industryData,
  function(values, callback) {
    //console.log(values);
    let IndustryFinancial = new IndustryFinancialModel(values);
    IndustryFinancial.save(function(err, resultIndustryFinancial) {
      //not entering in this function
      if (err) {
        console.log(err);
      } else if (resultIndustryFinancial) {
        console.log(resultIndustryFinancial);
        callback();
      }
    });
  },
  function(err) {
    if (err) {
      console.log(err);
    } else {
      console.log("========Here is callback =============");
    }
  }
);
console.log("========Send Response========");
res.json({
  success: true,
  message: " Industry has been successfully uploaded."
});

Output:
========Send Response========

0 个答案:

没有答案