2

I tried to get notification as well as the data in one query and i tried like below but this is giving only count,

 Categories.find(item).count().exec(function (err, result) {}

Can anyone please suggest help.

1
  • 1
    You'd have to execute the find, and in the callback check the length of result Commented Oct 25, 2016 at 6:35

2 Answers 2

3

You can't get your data like this way as @adeneo said in the comment.

Use find to get all records and then check length of records

Categories.find({query},function (err, result) {
  if(!err){
    if(Array.isArray(result))
       var count=result.length;
  }
});
Sign up to request clarification or add additional context in comments.

2 Comments

abdulbarik can you plese see this question?
-1

You can use @abdulbarik method if you want to fetch all the records.

If you are using a limit on the amount of data you need and you want the full count you can do the following:

Categories.count(query, function (err, count) {

        Categories.find(query)
            .limit(limit)
            .toArray(cb);
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.