Return a find command document for this query.
(
self, conn: _AgnosticConnection, apply_timeout: bool = False
)
| 1639 | self._as_command = cmd, self.db |
| 1640 | |
| 1641 | def as_command( |
| 1642 | self, conn: _AgnosticConnection, apply_timeout: bool = False |
| 1643 | ) -> tuple[dict[str, Any], str]: |
| 1644 | """Return a find command document for this query.""" |
| 1645 | # We use the command twice: on the wire and for command monitoring. |
| 1646 | # Generate it once, for speed and to avoid repeating side-effects. |
| 1647 | if self._as_command is not None: |
| 1648 | return self._as_command |
| 1649 | |
| 1650 | explain = "$explain" in self.spec |
| 1651 | cmd: dict[str, Any] = _gen_find_command( |
| 1652 | self.coll, |
| 1653 | self.spec, |
| 1654 | self.fields, |
| 1655 | self.ntoskip, |
| 1656 | self.limit, |
| 1657 | self.batch_size, |
| 1658 | self.flags, |
| 1659 | self.read_concern, |
| 1660 | self.collation, |
| 1661 | self.session, |
| 1662 | self.allow_disk_use, |
| 1663 | ) |
| 1664 | if explain: |
| 1665 | self.name = "explain" |
| 1666 | cmd = {"explain": cmd} |
| 1667 | conn.add_server_api(cmd) |
| 1668 | if self.session: |
| 1669 | self.session._apply_to(cmd, False, self.read_preference, conn) # type: ignore[arg-type] |
| 1670 | # Explain does not support readConcern. |
| 1671 | if not explain and not self.session.in_transaction: |
| 1672 | self.session._update_read_concern(cmd, conn) # type: ignore[arg-type] |
| 1673 | conn.send_cluster_time(cmd, self.session, self.client) # type: ignore[arg-type] |
| 1674 | # Support CSOT |
| 1675 | if apply_timeout: |
| 1676 | conn.apply_timeout(self.client, cmd=cmd) # type: ignore[arg-type] |
| 1677 | self._as_command = cmd, self.db |
| 1678 | return self._as_command |
| 1679 | |
| 1680 | def get_message( |
| 1681 | self, read_preference: _ServerMode, conn: _AgnosticConnection, use_cmd: bool = False |
no test coverage detected