Mongoose Model.count () does not call back, as documented

I follow an almost exact example of Model.count () from Mongoose docs:

User.count({ type: 'jungle' }, function (err, count) { console.log('I do not ever run'); }); 

This should print "I never run." Instead, it returns a Query object that should not happen, according to the docs, as I provide a callback. How to start callback function? Are there any circumstances where the callback does not start?

Using mongoose@3.6.17. Thank you!

+4
source share
1 answer

Before calling any model functions, make sure that you are connected to the database. Mongoose will simply queue the count request until you connect otherwise.

See this FAQ .

+5
source

Source: https://habr.com/ru/post/1498450/


All Articles