I'm trying to get the count all the data for the query and as well as get the limited data (for pagination) but both the console output gives me the count. What is that I'm doing wrong. Pls help
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);
});
});
Best Answer
As per MongoDB BLOG Here
In certain situations, count can be avoided for better performance
Counting things can be hard on a database. The obvious things to count, number of items in a collection or index, are easy to keep track of, but as soon as you start trying to count records based on a query, things get slower and slower. This is because the database has to do more work scanning practically every item in the database to see if it matches.MongoDB
does have anoptimisation
for a fastcount
where all the queried fields areindexed
and the query is based around equivalence, but only in that circumstance.