@@ -2144,18 +2144,18 @@ async def count_documents(
21442144 if comment is not None :
21452145 kwargs ["comment" ] = comment
21462146 pipeline .append ({"$group" : {"_id" : 1 , "n" : {"$sum" : 1 }}})
2147- cmd = {"aggregate" : self ._name , "pipeline" : pipeline , "cursor" : {}}
21482147 if "hint" in kwargs and not isinstance (kwargs ["hint" ], str ):
21492148 kwargs ["hint" ] = helpers_shared ._index_document (kwargs ["hint" ])
21502149 collation = validate_collation_or_none (kwargs .pop ("collation" , None ))
2151- cmd .update (kwargs )
21522150
21532151 async def _cmd (
21542152 session : Optional [AsyncClientSession ],
21552153 _server : Server ,
21562154 conn : AsyncConnection ,
21572155 read_preference : Optional [_ServerMode ],
21582156 ) -> int :
2157+ cmd : dict [str , Any ] = {"aggregate" : self ._name , "pipeline" : pipeline , "cursor" : {}}
2158+ cmd .update (kwargs )
21592159 result = await self ._aggregate_one_result (
21602160 conn , read_preference , cmd , collation , session
21612161 )
@@ -3194,26 +3194,27 @@ async def distinct(
31943194 """
31953195 if not isinstance (key , str ):
31963196 raise TypeError (f"key must be an instance of str, not { type (key )} " )
3197- cmd = {"distinct" : self ._name , "key" : key }
31983197 if filter is not None :
31993198 if "query" in kwargs :
32003199 raise ConfigurationError ("can't pass both filter and query" )
32013200 kwargs ["query" ] = filter
32023201 collation = validate_collation_or_none (kwargs .pop ("collation" , None ))
3203- cmd .update (kwargs )
3204- if comment is not None :
3205- cmd ["comment" ] = comment
32063202 if hint is not None :
32073203 if not isinstance (hint , str ):
32083204 hint = helpers_shared ._index_document (hint )
3209- cmd ["hint" ] = hint # type: ignore[assignment]
32103205
32113206 async def _cmd (
32123207 session : Optional [AsyncClientSession ],
32133208 _server : Server ,
32143209 conn : AsyncConnection ,
32153210 read_preference : Optional [_ServerMode ],
32163211 ) -> list : # type: ignore[type-arg]
3212+ cmd = {"distinct" : self ._name , "key" : key }
3213+ cmd .update (kwargs )
3214+ if comment is not None :
3215+ cmd ["comment" ] = comment
3216+ if hint is not None :
3217+ cmd ["hint" ] = hint # type: ignore[assignment]
32173218 return (
32183219 await self ._command (
32193220 conn ,
@@ -3248,27 +3249,26 @@ async def _find_and_modify(
32483249 f"return_document must be ReturnDocument.BEFORE or ReturnDocument.AFTER, not { type (return_document )} "
32493250 )
32503251 collation = validate_collation_or_none (kwargs .pop ("collation" , None ))
3251- cmd = {"findAndModify" : self ._name , "query" : filter , "new" : return_document }
3252- if let is not None :
3253- common .validate_is_mapping ("let" , let )
3254- cmd ["let" ] = let
3255- cmd .update (kwargs )
3256- if projection is not None :
3257- cmd ["fields" ] = helpers_shared ._fields_list_to_dict (projection , "projection" )
3258- if sort is not None :
3259- cmd ["sort" ] = helpers_shared ._index_document (sort )
3260- if upsert is not None :
3261- validate_boolean ("upsert" , upsert )
3262- cmd ["upsert" ] = upsert
32633252 if hint is not None :
32643253 if not isinstance (hint , str ):
32653254 hint = helpers_shared ._index_document (hint )
3266-
3267- write_concern = self ._write_concern_for_cmd (cmd , session )
3255+ write_concern = self ._write_concern_for_cmd (kwargs , session )
32683256
32693257 async def _find_and_modify_helper (
32703258 session : Optional [AsyncClientSession ], conn : AsyncConnection , retryable_write : bool
32713259 ) -> Any :
3260+ cmd = {"findAndModify" : self ._name , "query" : filter , "new" : return_document }
3261+ if let is not None :
3262+ common .validate_is_mapping ("let" , let )
3263+ cmd ["let" ] = let
3264+ cmd .update (kwargs )
3265+ if projection is not None :
3266+ cmd ["fields" ] = helpers_shared ._fields_list_to_dict (projection , "projection" )
3267+ if sort is not None :
3268+ cmd ["sort" ] = helpers_shared ._index_document (sort )
3269+ if upsert is not None :
3270+ validate_boolean ("upsert" , upsert )
3271+ cmd ["upsert" ] = upsert
32723272 acknowledged = write_concern .acknowledged
32733273 if array_filters is not None :
32743274 if not acknowledged :
0 commit comments