From 5ee4b4a5ac4193dc8add4168c0262f0786844a4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wilson=20J=C3=BAnior?= Date: Fri, 16 Dec 2011 11:49:20 -0200 Subject: [PATCH] added count/len for ListResult --- mongoengine/queryset.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mongoengine/queryset.py b/mongoengine/queryset.py index 23e581b8..2f902273 100644 --- a/mongoengine/queryset.py +++ b/mongoengine/queryset.py @@ -376,6 +376,15 @@ class ListResult(object): def rewind(self): self._cursor.rewind() + def count(self): + """ + Count the selected elements in the query. + """ + return self._cursor.count(with_limit_and_skip=True) + + def __len__(self): + return self.count() + def __iter__(self): return self