For循环迭代器在执行mongoose find之前递增

时间:2017-08-22 15:29:01

标签: node.js mongodb express mongoose

在下面的代码中,当我从0到1运行FOR循环时,由于我在FOR循环的开头添加了一个控制台日志,Console打印0,1然后执行mongoose find语句。

 for (var i = 0; i < req.body.seatNo.length; i++) {
     console.log(i);
     var pname = req.body.name[i];
     //console.log(pname);
     var page = req.body.age[i]
     //console.log(page);
     busModel.findOne({
         $and: [{
             "ticket.seatNumber": req.body.seatNo[i]
      }, {
             "dateOfJourney": dataG
      }, {
             "ticket.reserved": false
      }]
     }, function (err, doc) {
         duplicateBookCheck.push(i);
         if (doc) {
             console.log("inside doc")
             doc.save(function (err) {
                 if (err) {
                     console.log('save error');
                 } else {
                     //hidden
                 }
             })
         }
     });
 }

0 个答案:

没有答案