Skip to content
This repository was archived by the owner on Dec 1, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mongoengine/context_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def __repr__(self):
def _get_count(self):
""" Get the number of queries. """
ignore_query = {"ns": {"$ne": "%s.system.indexes" % self.db.name}}
count = self.db.system.profile.find(ignore_query).count() - self.counter
count = self.db.system.profile.count_documents(filter=ignore_query) - self.counter
self.counter += 1
return count

Expand Down
19 changes: 18 additions & 1 deletion mongoengine/queryset/queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,26 @@ def count(self, with_limit_and_skip=True):

if with_limit_and_skip and self._len is not None:
return self._len
count = self._cursor.count(with_limit_and_skip=with_limit_and_skip)

options = {}
if with_limit_and_skip:
if self._limit is not None:
options["limit"] = self._limit
if self._skip is not None:
options["skip"] = self._skip
if self._hint not in (-1, None):
options["hint"] = self._hint

if self._query or options:
count = self._cursor.collection.count_documents(
filter=self._query, **options
)
else:
count = self._cursor.collection.estimated_document_count()

if with_limit_and_skip:
self._len = count

return count

def delete(self, write_concern=None, _from_doc_delete=False):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_version(version_tuple):
long_description=LONG_DESCRIPTION,
platforms=['any'],
classifiers=CLASSIFIERS,
install_requires=['pymongo>=3.0,<3.14'],
install_requires=['pymongo>=3.7'],
test_suite='nose.collector',
**extra_opts
)
2 changes: 1 addition & 1 deletion tests/test_context_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def test_query_counter(self):
self.assertEqual(0, q)

for i in range(1, 51):
db.test.find({}).count()
db.test.estimated_document_count()

self.assertEqual(50, q)

Expand Down