如何在猫鼬中按日期查询?

时间:2020-12-28 22:06:24

标签: date datetime mongoose mongoose-schema

I wanns search all entries on a specific date

`var userSchema = new Schema({ 名称:字符串, 电子邮件:字符串, }, { 时间戳:true }); // 这里的日期是以 ISO 格式存储的

router.get('/date', (req, res) => {
const dateTodetch = '2020-12-26' //我们要获取所有记录的日期,格式为“yyyy-mm-dd”

//Since @26 it could be on anytime, so i'll search from 0 to 23.59
UserModel.find({
    createdAt: {
        $gte: "2020-12-26", 
        $lt: "2020-12-27"
    }
}).exec((err, rec) => {
    if(err) res.status(400).json(err)
    res.json(rec)
})

})

//但我一直在得到 [] 作为答案 Description

0 个答案:

没有答案