Sales.find({
"email":req.body.email,
"createAt": {
"$gte": firstDayOfMonth(month),
"$lte": lastDayOfMonth(month)
},
"sort":{
createAt: -1 //Sort by Date Added DESC
}
}, function(err,response){
callback(err,response);
});
知道为什么这个 Mongoose 查询不起作用吗?我确定这是排序问题,因为当我删除排序部分时,我能够获取一些数据。
最佳答案
请尝试此代码,
var queryOptions = {
$and: [{
'createAt': {
"$gte": firstDayOfMonth(month),
"$lte": lastDayOfMonth(month)
}
}, {
'email': req.body.email
}]
}
Sales
.find(queryOptions)
.sort('-createAt')
.exec(function(err, response) {
return res.status(200).json(response);
}).catch(function(error) {
return res.status(500).json(error);
});
关于javascript - Mongoose 排序不适用于 find(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40290409/