@@ -62,7 +62,7 @@ async def command(
6262 conn : AsyncConnection ,
6363 dbname : str ,
6464 spec : MutableMapping [str , Any ],
65- is_mongos : bool ,
65+ is_mongos : bool , # noqa: ARG001
6666 read_preference : Optional [_ServerMode ],
6767 codec_options : CodecOptions [_DocumentType ],
6868 session : Optional [AsyncClientSession ],
@@ -76,7 +76,6 @@ async def command(
7676 parse_write_concern_error : bool = False ,
7777 collation : Optional [_CollationIn ] = None ,
7878 compression_ctx : Union [SnappyContext , ZlibContext , ZstdContext , None ] = None ,
79- use_op_msg : bool = False ,
8079 unacknowledged : bool = False ,
8180 user_fields : Optional [Mapping [str , Any ]] = None ,
8281 exhaust_allowed : bool = False ,
@@ -102,22 +101,17 @@ async def command(
102101 field in the command response.
103102 :param collation: The collation for this command.
104103 :param compression_ctx: optional compression Context.
105- :param use_op_msg: True if we should use OP_MSG.
106104 :param unacknowledged: True if this is an unacknowledged command.
107105 :param user_fields: Response fields that should be decoded
108106 using the TypeDecoders from codec_options, passed to
109107 bson._decode_all_selective.
110108 :param exhaust_allowed: True if we should enable OP_MSG exhaustAllowed.
111109 """
112110 name = next (iter (spec ))
113- ns = dbname + ".$cmd"
114111 speculative_hello = False
115112
116113 # Publish the original command document, perhaps with lsid and $clusterTime.
117114 orig = spec
118- if is_mongos and not use_op_msg :
119- assert read_preference is not None
120- spec = message ._maybe_add_read_preference (spec , read_preference )
121115 if read_concern and not (session and session .in_transaction ):
122116 if read_concern .level :
123117 spec ["readConcern" ] = read_concern .document
@@ -142,20 +136,15 @@ async def command(
142136 conn .apply_timeout (client , spec )
143137 _csot .apply_write_concern (spec , write_concern )
144138
145- if use_op_msg :
146- flags = _OpMsg .MORE_TO_COME if unacknowledged else 0
147- flags |= _OpMsg .EXHAUST_ALLOWED if exhaust_allowed else 0
148- request_id , msg , size , max_doc_size = message ._op_msg (
149- flags , spec , dbname , read_preference , codec_options , ctx = compression_ctx
150- )
151- # If this is an unacknowledged write then make sure the encoded doc(s)
152- # are small enough, otherwise rely on the server to return an error.
153- if unacknowledged and max_bson_size is not None and max_doc_size > max_bson_size :
154- message ._raise_document_too_large (name , size , max_bson_size )
155- else :
156- request_id , msg , size = message ._query (
157- 0 , ns , 0 , - 1 , spec , None , codec_options , compression_ctx
158- )
139+ flags = _OpMsg .MORE_TO_COME if unacknowledged else 0
140+ flags |= _OpMsg .EXHAUST_ALLOWED if exhaust_allowed else 0
141+ request_id , msg , size , max_doc_size = message ._op_msg (
142+ flags , spec , dbname , read_preference , codec_options , ctx = compression_ctx
143+ )
144+ # If this is an unacknowledged write then make sure the encoded doc(s)
145+ # are small enough, otherwise rely on the server to return an error.
146+ if unacknowledged and max_bson_size is not None and max_doc_size > max_bson_size :
147+ message ._raise_document_too_large (name , size , max_bson_size )
159148
160149 if max_bson_size is not None and size > max_bson_size + message ._COMMAND_OVERHEAD :
161150 message ._raise_document_too_large (name , size , max_bson_size + message ._COMMAND_OVERHEAD )
@@ -190,7 +179,7 @@ async def command(
190179
191180 try :
192181 await async_sendall (conn .conn .get_conn , msg )
193- if use_op_msg and unacknowledged :
182+ if unacknowledged :
194183 # Unacknowledged, fake a successful command response.
195184 reply = None
196185 response_doc : _DocumentOut = {"ok" : 1 }
0 commit comments