按日期查询不返回结果

时间:2020-07-18 20:46:08

标签: node.js mongodb mongoose

我尝试查询expiration_date字段,该字段返回您今天的日期,我正在尝试使用该方法,但是它不返回任何结果

router.get('/date/expired/', async (req, res, next) => {
    const start = new Date()
    start.setHours(0, 0, 0, 0)

    const end = new Date()
    end.setHours(23, 59, 59, 999)
    try {
      const data = await Tarea.find({
        fecha_vencimiento: {
          $gte: start,
          $lt: end
        }
      })

      res.status(200).json({
        data
      })
    } catch (err) {
      next(err)
    }
  })

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试使用moment.js定义日期:

let start = moment().format('YYYY-MM-DD')
let end = moment().add(1,'days').format('YYYY-MM-DD');

我希望它对您有用。