MCPcopy Index your code
hub / github.com/MongoEngine/mongoengine / _cursor

Method _cursor

mongoengine/queryset/base.py:1704–1760  ·  view source on GitHub ↗

Return a PyMongo cursor object corresponding to this queryset.

(self)

Source from the content-addressed store, hash-verified

1702
1703 @property
1704 def _cursor(self):
1705 """Return a PyMongo cursor object corresponding to this queryset."""
1706
1707 # If _cursor_obj already exists, return it immediately.
1708 if self._cursor_obj is not None:
1709 return self._cursor_obj
1710
1711 # Create a new PyMongo cursor.
1712 # XXX In PyMongo 3+, we define the read preference on a collection
1713 # level, not a cursor level. Thus, we need to get a cloned collection
1714 # object using `with_options` first.
1715 if self._read_preference is not None or self._read_concern is not None:
1716 self._cursor_obj = self._collection.with_options(
1717 read_preference=self._read_preference, read_concern=self._read_concern
1718 ).find(self._query, **self._cursor_args)
1719 else:
1720 self._cursor_obj = self._collection.find(self._query, **self._cursor_args)
1721
1722 # Apply "where" clauses to cursor
1723 if self._where_clause:
1724 where_clause = self._sub_js_fields(self._where_clause)
1725 self._cursor_obj.where(where_clause)
1726
1727 # Apply ordering to the cursor.
1728 # XXX self._ordering can be equal to:
1729 # * None if we didn't explicitly call order_by on this queryset.
1730 # * A list of PyMongo-style sorting tuples.
1731 # * An empty list if we explicitly called order_by() without any
1732 # arguments. This indicates that we want to clear the default
1733 # ordering.
1734 if self._ordering:
1735 # explicit ordering
1736 self._cursor_obj.sort(self._ordering)
1737 elif self._ordering is None and self._document._meta["ordering"]:
1738 # default ordering
1739 order = self._get_order_by(self._document._meta["ordering"])
1740 self._cursor_obj.sort(order)
1741
1742 if self._limit is not None:
1743 self._cursor_obj.limit(self._limit)
1744
1745 if self._skip is not None:
1746 self._cursor_obj.skip(self._skip)
1747
1748 if self._hint != -1:
1749 self._cursor_obj.hint(self._hint)
1750
1751 if self._collation is not None:
1752 self._cursor_obj.collation(self._collation)
1753
1754 if self._batch_size is not None:
1755 self._cursor_obj.batch_size(self._batch_size)
1756
1757 if self._comment is not None:
1758 self._cursor_obj.comment(self._comment)
1759
1760 return self._cursor_obj
1761

Callers

nothing calls this directly

Calls 9

_sub_js_fieldsMethod · 0.95
_get_order_byMethod · 0.95
whereMethod · 0.80
limitMethod · 0.80
skipMethod · 0.80
hintMethod · 0.80
collationMethod · 0.80
batch_sizeMethod · 0.80
commentMethod · 0.80

Tested by

no test coverage detected