randomuser1
randomuser1

Reputation: 2803

How can I add another condition to my search query in mongoose.js?

User.find({problem_no:1})
.count()
.exec(function (err, count) {
    res.send({user_problem_no_1: count})
})

Above is my query and it counts all the entries in my collection that says problem_no has a value 1. I want to include here also verification of a date, so that I want to count only entries where problem_no == 1 and that created_at is greater or equal someDate. How should I modify this query to perform it?

Upvotes: 0

Views: 80

Answers (2)

Sprotte
Sprotte

Reputation: 541

with and you can do this

   User.find()
    .and([
      {problem_no: 1},
      {'created_at': date}} // i think in millieseconds
    ])
    .sort({created_at: -1})
    .exec(function (err, user) {
      // do stuff
    }

Upvotes: 0

zangw
zangw

Reputation: 48526

Try this one with $gte

User.find({problem_no:1, create_at: {$gte: someDate}})

Or with gte()

User.find({problem_no:1}).where('create_at').gte(someDate)...

Upvotes: 1

Related Questions