Execute a command over the socket, or raise socket.error. :param conn: a AsyncConnection instance :param dbname: name of the database on which to run the command :param spec: a command document as an ordered dict type, eg SON. :param is_mongos: are we connected to a mongos? :par
(
conn: AsyncConnection,
dbname: str,
spec: MutableMapping[str, Any],
is_mongos: bool,
read_preference: Optional[_ServerMode],
codec_options: CodecOptions[_DocumentType],
session: Optional[AsyncClientSession],
client: Optional[AsyncMongoClient[Any]],
check: bool = True,
allowable_errors: Optional[Sequence[Union[str, int]]] = None,
address: Optional[_Address] = None,
listeners: Optional[_EventListeners] = None,
max_bson_size: Optional[int] = None,
read_concern: Optional[ReadConcern] = None,
parse_write_concern_error: bool = False,
collation: Optional[_CollationIn] = None,
compression_ctx: Union[SnappyContext, ZlibContext, ZstdContext, None] = None,
use_op_msg: bool = False,
unacknowledged: bool = False,
user_fields: Optional[Mapping[str, Any]] = None,
exhaust_allowed: bool = False,
write_concern: Optional[WriteConcern] = None,
)
| 59 | |
| 60 | |
| 61 | async def command( |
| 62 | conn: AsyncConnection, |
| 63 | dbname: str, |
| 64 | spec: MutableMapping[str, Any], |
| 65 | is_mongos: bool, |
| 66 | read_preference: Optional[_ServerMode], |
| 67 | codec_options: CodecOptions[_DocumentType], |
| 68 | session: Optional[AsyncClientSession], |
| 69 | client: Optional[AsyncMongoClient[Any]], |
| 70 | check: bool = True, |
| 71 | allowable_errors: Optional[Sequence[Union[str, int]]] = None, |
| 72 | address: Optional[_Address] = None, |
| 73 | listeners: Optional[_EventListeners] = None, |
| 74 | max_bson_size: Optional[int] = None, |
| 75 | read_concern: Optional[ReadConcern] = None, |
| 76 | parse_write_concern_error: bool = False, |
| 77 | collation: Optional[_CollationIn] = None, |
| 78 | compression_ctx: Union[SnappyContext, ZlibContext, ZstdContext, None] = None, |
| 79 | use_op_msg: bool = False, |
| 80 | unacknowledged: bool = False, |
| 81 | user_fields: Optional[Mapping[str, Any]] = None, |
| 82 | exhaust_allowed: bool = False, |
| 83 | write_concern: Optional[WriteConcern] = None, |
| 84 | ) -> _DocumentType: |
| 85 | """Execute a command over the socket, or raise socket.error. |
| 86 | |
| 87 | :param conn: a AsyncConnection instance |
| 88 | :param dbname: name of the database on which to run the command |
| 89 | :param spec: a command document as an ordered dict type, eg SON. |
| 90 | :param is_mongos: are we connected to a mongos? |
| 91 | :param read_preference: a read preference |
| 92 | :param codec_options: a CodecOptions instance |
| 93 | :param session: optional AsyncClientSession instance. |
| 94 | :param client: optional AsyncMongoClient instance for updating $clusterTime. |
| 95 | :param check: raise OperationFailure if there are errors |
| 96 | :param allowable_errors: errors to ignore if `check` is True |
| 97 | :param address: the (host, port) of `conn` |
| 98 | :param listeners: An instance of :class:`~pymongo.monitoring.EventListeners` |
| 99 | :param max_bson_size: The maximum encoded bson size for this server |
| 100 | :param read_concern: The read concern for this command. |
| 101 | :param parse_write_concern_error: Whether to parse the ``writeConcernError`` |
| 102 | field in the command response. |
| 103 | :param collation: The collation for this command. |
| 104 | :param compression_ctx: optional compression Context. |
| 105 | :param use_op_msg: True if we should use OP_MSG. |
| 106 | :param unacknowledged: True if this is an unacknowledged command. |
| 107 | :param user_fields: Response fields that should be decoded |
| 108 | using the TypeDecoders from codec_options, passed to |
| 109 | bson._decode_all_selective. |
| 110 | :param exhaust_allowed: True if we should enable OP_MSG exhaustAllowed. |
| 111 | """ |
| 112 | name = next(iter(spec)) |
| 113 | ns = dbname + ".$cmd" |
| 114 | speculative_hello = False |
| 115 | |
| 116 | # Publish the original command document, perhaps with lsid and $clusterTime. |
| 117 | orig = spec |
| 118 | if is_mongos and not use_op_msg: |
no test coverage detected