简体   繁体   English

如何在mongoose.js中向搜索查询添加其他条件?

[英]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 . 上面是我的查询,它对我的​​集合中所有problem_no的值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 . 我想在这里还包括一个日期验证,以便只计算在problem_no == 1created_at大于或等于someDate How should I modify this query to perform it? 我应该如何修改此查询以执行它?

Try this one with $gte 尝试一下$gte

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

Or with gte() 或与gte()

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

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
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM