@@ -2144,18 +2144,18 @@ async def count_documents(
2144
2144
if comment is not None :
2145
2145
kwargs ["comment" ] = comment
2146
2146
pipeline .append ({"$group" : {"_id" : 1 , "n" : {"$sum" : 1 }}})
2147
- cmd = {"aggregate" : self ._name , "pipeline" : pipeline , "cursor" : {}}
2148
2147
if "hint" in kwargs and not isinstance (kwargs ["hint" ], str ):
2149
2148
kwargs ["hint" ] = helpers_shared ._index_document (kwargs ["hint" ])
2150
2149
collation = validate_collation_or_none (kwargs .pop ("collation" , None ))
2151
- cmd .update (kwargs )
2152
2150
2153
2151
async def _cmd (
2154
2152
session : Optional [AsyncClientSession ],
2155
2153
_server : Server ,
2156
2154
conn : AsyncConnection ,
2157
2155
read_preference : Optional [_ServerMode ],
2158
2156
) -> int :
2157
+ cmd : dict [str , Any ] = {"aggregate" : self ._name , "pipeline" : pipeline , "cursor" : {}}
2158
+ cmd .update (kwargs )
2159
2159
result = await self ._aggregate_one_result (
2160
2160
conn , read_preference , cmd , collation , session
2161
2161
)
@@ -3194,26 +3194,27 @@ async def distinct(
3194
3194
"""
3195
3195
if not isinstance (key , str ):
3196
3196
raise TypeError (f"key must be an instance of str, not { type (key )} " )
3197
- cmd = {"distinct" : self ._name , "key" : key }
3198
3197
if filter is not None :
3199
3198
if "query" in kwargs :
3200
3199
raise ConfigurationError ("can't pass both filter and query" )
3201
3200
kwargs ["query" ] = filter
3202
3201
collation = validate_collation_or_none (kwargs .pop ("collation" , None ))
3203
- cmd .update (kwargs )
3204
- if comment is not None :
3205
- cmd ["comment" ] = comment
3206
3202
if hint is not None :
3207
3203
if not isinstance (hint , str ):
3208
3204
hint = helpers_shared ._index_document (hint )
3209
- cmd ["hint" ] = hint # type: ignore[assignment]
3210
3205
3211
3206
async def _cmd (
3212
3207
session : Optional [AsyncClientSession ],
3213
3208
_server : Server ,
3214
3209
conn : AsyncConnection ,
3215
3210
read_preference : Optional [_ServerMode ],
3216
3211
) -> 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]
3217
3218
return (
3218
3219
await self ._command (
3219
3220
conn ,
@@ -3248,27 +3249,26 @@ async def _find_and_modify(
3248
3249
f"return_document must be ReturnDocument.BEFORE or ReturnDocument.AFTER, not { type (return_document )} "
3249
3250
)
3250
3251
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
3263
3252
if hint is not None :
3264
3253
if not isinstance (hint , str ):
3265
3254
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 )
3268
3256
3269
3257
async def _find_and_modify_helper (
3270
3258
session : Optional [AsyncClientSession ], conn : AsyncConnection , retryable_write : bool
3271
3259
) -> 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
3272
3272
acknowledged = write_concern .acknowledged
3273
3273
if array_filters is not None :
3274
3274
if not acknowledged :
0 commit comments