2016-01-24 46 views
0
User.find({problem_no:1}) 
.count() 
.exec(function (err, count) { 
    res.send({user_problem_no_1: count}) 
}) 

以上是我的查詢,它統計了我收藏中的所有條目,說problem_no的值爲1。我想在此也包括日期的驗證,以便我只計算其中problem_no == 1created_at大於或等於someDate的條目。我應該如何修改這個查詢來執行它?如何向mongoose.js中的搜索查詢添加其他條件?

回答

1

試試這個與$gte

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

或用gte()

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

用你能做到這一點

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