mongoose计数返回错误的数据

Meeting.count(countQuery).then(countBookings) .then(findUser) . // a few more then blocks, that are not relevant to my problem . . .catch((err) => { console.log('The meeting error is ', err); }) 

这是我的计数查询对象:

 let countQuery = { startDate: {$gte: date1, $lte: date2}, teamId: req.body.teamId }; 

这是我的预约function:

 const countBookings = (data) => { console.log('reached countBookings') if (data >= 6 || data + bookingDet.length > 6) { res.status(403).json({message: 'Can\'t book for more than 3 hours in a day'}) throw new Error('More than 3 bookings in a day are not allowed.') } else { return true } } 

这是我面临的情况。 我需要防止用户预订超过6个插槽。 出于testing的目的,我第一次预订了2个插槽,然后我能够预定6个插槽。 而当我试图再次预订,这一次它的工作。

我试了console.log()并重复了同样的步骤,结果mongoose不算第一次预订。 但是当我第三次尝试时,我收到了来自count查询的6个预订。 当我通过mongoshelltesting,并在第一次预订2个插槽后,它返回了我正确的数量。

我试过find()但问题是一样的? 为什么发生?