MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / command

Function command

pymongo/synchronous/network.py:61–298  ·  view source on GitHub ↗

Execute a command over the socket, or raise socket.error. :param conn: a Connection 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? :param re

(
    conn: Connection,
    dbname: str,
    spec: MutableMapping[str, Any],
    is_mongos: bool,
    read_preference: Optional[_ServerMode],
    codec_options: CodecOptions[_DocumentType],
    session: Optional[ClientSession],
    client: Optional[MongoClient[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,
)

Source from the content-addressed store, hash-verified

59
60
61def command(
62 conn: Connection,
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[ClientSession],
69 client: Optional[MongoClient[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 Connection 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 ClientSession instance.
94 :param client: optional MongoClient 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:

Callers 4

commandMethod · 0.90
do_taskMethod · 0.50
do_taskMethod · 0.50
do_taskMethod · 0.50

Calls 15

_debug_logFunction · 0.90
sendallFunction · 0.90
receive_messageFunction · 0.90
_decode_all_selectiveFunction · 0.90
nextFunction · 0.85
iterFunction · 0.85
publish_command_startMethod · 0.80
_update_read_concernMethod · 0.45
encryptMethod · 0.45

Tested by 3

do_taskMethod · 0.40
do_taskMethod · 0.40
do_taskMethod · 0.40