Return a PyMongo cursor object corresponding to this queryset.
(self)
| 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 |
nothing calls this directly
no test coverage detected