#Query objects by date

2 messages · Page 1 of 1 (latest)

raven orchid
#

I am using Mongoose with Express. Need a query which must meet the following criteria: 1. property depo.depo_status must be equal to DepoStatus.ACTIVE, and depo.valid_to date must be within one week or less since today. Any ideas?

raven orchid
#

Found a solution:

 const sevenDaysFromNow = new Date().setDate(new Date().getDate() + 7)
        const depos = await DepoModel.find({
            valid_to: { '$lte': sevenDaysFromNow },
            depo_status: DepoStatus.ACTIVE
        })

docs: https://mongoosejs.com/docs/tutorials/dates.html