MongoDB计算并获取有限的数据
我正在尝试计算查询的所有数据,以及获取有限的数据(用于分页),但控制台输出都给了我计数。那是什么我做错了。请帮忙
const curFind = fbUser.find(find, 'firstName gender age birthday facebookId profileURL email imageUrl preferences blocked flames likes rejects location reported')
curFind.count(function(e, count) {
console.log(count);
curFind.skip(0).limit(10).hint( { $natural : 1 } ).exec(function(err, data) {
console.log(data);
});
});
回答如下:
如果在执行curFind
之前和之后打印count
对象,您会注意到Query
对象的op
字段从find
变为count
。它可能是也可能不是猫鼬的错误,但解释了为什么你再次计数。我通常不会重复使用查询对象 - 这也可以解决您的问题。
MongoDB计算并获取有限的数据
我正在尝试计算查询的所有数据,以及获取有限的数据(用于分页),但控制台输出都给了我计数。那是什么我做错了。请帮忙
const curFind = fbUser.find(find, 'firstName gender age birthday facebookId profileURL email imageUrl preferences blocked flames likes rejects location reported')
curFind.count(function(e, count) {
console.log(count);
curFind.skip(0).limit(10).hint( { $natural : 1 } ).exec(function(err, data) {
console.log(data);
});
});
回答如下:
如果在执行curFind
之前和之后打印count
对象,您会注意到Query
对象的op
字段从find
变为count
。它可能是也可能不是猫鼬的错误,但解释了为什么你再次计数。我通常不会重复使用查询对象 - 这也可以解决您的问题。