我在我的应用中使用Q模块。我想使用$ limit和$ sort函数来查询mongoDB, 我也在使用Q.nbind()进行查询
var Q = require('q');
var mongoose = require('mongoose');
var RequestPrayers = mongoose.model('requestPrayers');
var RPrayerfind = Q.nbind(RequestPrayers.find, RequestPrayers);
function getSingleRParyerInfo(FrndID){
var id = FrndID
var prayerInfo={prayersInfo:''};
return RPrayerfind({userID:id, is_notPrivate:true})
// return find()
// ^^^^^^ Rule 1
.then(function(Prayers) {
// ^^^^^ Rule 3
if (!Prayers){
prayerInfo.prayersInfo = '';
// console.log(User)
}else{
prayerInfo.prayersInfo = Prayers;
//console.log(User)
}
return prayerInfo;
// ^^^^^^ Rule 3b
});
}
请问我应该用什么来获得我想要的结果
返回RPrayerfind({userID:id,is_notPrivate:true})。limit(2);
OR
返回RPrayerfind({userID:id,is_notPrivate:true},{$ limit:2})
答案 0 :(得分:2)
这很简单,只需查看以下代码:
var q = require('q');
var findSomeThing = q.nbind(SomeThing.find,SomeThing);
SomeThing({"someId":"someIdValue"},{},{limit:2}).done(function(data){
//2 records will be retrieved here
console.log(data);
});
希望这能帮到你!
答案 1 :(得分:0)
你可以像这样简单地使用它
RPrayerFind({用户名:1},{},{ '$限制':10, '$跳过':300})