Skip to content

Commit

Permalink
QuerySet count vs len MongoEngine#937
Browse files Browse the repository at this point in the history
Current documentation does not consider performance issues in using len instead of count.
MongoEngine#937
  • Loading branch information
marcoskv committed Jul 26, 2015
1 parent f8890ca commit a70ef55
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/guide/querying.rst
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ way of achieving this::

num_users = len(User.objects)

Even if len() is the Pythonic way of counting results, keep in mind that if you concerned about performance, :meth:`~mongoengine.queryset.QuerySet.count` is the way to go since it only execute a server side count query, while len() retrieves the results, places them in cache, and finally counts them. If we compare the performance of the two operations, len() is much slower than :meth:`~mongoengine.queryset.QuerySet.count`.

Further aggregation
-------------------
You may sum over the values of a specific field on documents using
Expand Down

0 comments on commit a70ef55

Please sign in to comment.