Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use count() ? #17

Closed
xdamman opened this issue Jun 28, 2010 · 5 comments
Closed

How to use count() ? #17

xdamman opened this issue Jun 28, 2010 · 5 comments

Comments

@xdamman
Copy link

xdamman commented Jun 28, 2010

I tried many things but I can't make count() work.
Based on the documentation, it is supposed to work this may:
User.find({username: 'john'}).count()

I've got this error:
DEBUG: TypeError: undefined is not a function
at CALL_NON_FUNCTION (native)
at /lib/mongoose/lib/model.js:177:9

I've also tried with
User.find({username: 'john'}).count(fn(r) { sys.debug(r); })
Or
User.count();
...

Thanks for your support.

@xdamman
Copy link
Author

xdamman commented Jun 28, 2010

The error up here is where I test with User.count(), with User.find().count() I have the following error:
Error: Object [object Object] has no method 'count'

@xdamman
Copy link
Author

xdamman commented Jun 28, 2010

I've solved the issue.
The correct code is:
User.count({},function(count) { } )

@KathRains
Copy link

KathRains commented Aug 15, 2017

I encountered with the same problem, the correct code is:

User.count({},function(err, count) { } )

If you omit the err parameter the count result will be always null (if no error occured).

@cesargdm
Copy link

cesargdm commented Feb 14, 2019

DeprecationWarning: collection.count is deprecated, and will be removed in a future version. Use collection.countDocuments or collection.estimatedDocumentCount instead

@vkarpov15
Copy link
Collaborator

@Automattic Automattic locked as resolved and limited conversation to collaborators Feb 16, 2019
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants