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

QuerySet count vs len #937

Closed
marcoskv opened this issue Apr 8, 2015 · 2 comments
Closed

QuerySet count vs len #937

marcoskv opened this issue Apr 8, 2015 · 2 comments

Comments

@marcoskv
Copy link
Contributor

marcoskv commented Apr 8, 2015

The MongoEngine documentation recommends to use len to count results, because it is more Pythonic.

count() executes a server side count query, while len() retrieves the results, places them in cache, and then counts them.

If we compare the performance of the two operations, len() is super slow compared to count().

It would be better to explain that properly in the documentation.

@mmellison
Copy link
Contributor

Feel free to throw up a Pull Request for updating the documentation. We are trying to clean up our back log of issues but we currently have a lot of issues and bugs to work through. Any help would be appreciated. :)

marcoskv added a commit to marcoskv/mongoengine that referenced this issue Jul 26, 2015
Current documentation does not consider performance issues in using len instead of count.
MongoEngine#937
DavidBord added a commit that referenced this issue Aug 1, 2015
@wojcikstefan
Copy link
Member

The documentation around this is better now, making it clear that Doc.objects.count is the way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants