Mongoose query by date

mongodb, mongodb-query, mongoose, node.js

Solution

Use `$gte` like this :

Example.find({
    validUntil: {
        $gte: new Date(2016,09,30)
    }
})

Problem

I want to query mongoDB with document structure like this: ``` var ExampleSchema = mongoose.Schema({ createdAt: { type: Date, default: Date.now }, validUntil: Date, name: String }); ``` and need it to return only valid documents, i.e. where validUntil is greater than current time. This doesn't work, mongoose returns all documents: ``` var d = new Date(); var n = d.toISOString(); Example.find({ '$where': 'validUntil'>n }) ```

Original source