get docs with date intervals mongoose

Solutions on MaxInterview for get docs with date intervals mongoose by the best coders in the world

showing results for - "get docs with date intervals mongoose"
Jeb
26 Jul 2018
1const moment = require('moment')
2
3const today = moment().startOf('day')
4
5MyModel.find({
6  createdAt: {
7    $gte: today.toDate(),
8    $lte: moment(today).endOf('day').toDate()
9  }
10})
11
Rayan
16 Feb 2018
1db.posts.find({ //query today up to tonight
2    created_on: {
3        $gte: new Date(2012, 7, 14), 
4        $lt: new Date(2012, 7, 15)
5    }
6})
7