Skip to content

Commit c0d6244

Browse files
committed
Merge branch 'master' of github.com:mongodb/mongo-python-driver
2 parents e91b817 + 668bd82 commit c0d6244

File tree

2 files changed

+42
-42
lines changed

2 files changed

+42
-42
lines changed

pymongo/asynchronous/collection.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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:

pymongo/synchronous/collection.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,18 +2143,18 @@ def count_documents(
21432143
if comment is not None:
21442144
kwargs["comment"] = comment
21452145
pipeline.append({"$group": {"_id": 1, "n": {"$sum": 1}}})
2146-
cmd = {"aggregate": self._name, "pipeline": pipeline, "cursor": {}}
21472146
if "hint" in kwargs and not isinstance(kwargs["hint"], str):
21482147
kwargs["hint"] = helpers_shared._index_document(kwargs["hint"])
21492148
collation = validate_collation_or_none(kwargs.pop("collation", None))
2150-
cmd.update(kwargs)
21512149

21522150
def _cmd(
21532151
session: Optional[ClientSession],
21542152
_server: Server,
21552153
conn: Connection,
21562154
read_preference: Optional[_ServerMode],
21572155
) -> int:
2156+
cmd: dict[str, Any] = {"aggregate": self._name, "pipeline": pipeline, "cursor": {}}
2157+
cmd.update(kwargs)
21582158
result = self._aggregate_one_result(conn, read_preference, cmd, collation, session)
21592159
if not result:
21602160
return 0
@@ -3187,26 +3187,27 @@ def distinct(
31873187
"""
31883188
if not isinstance(key, str):
31893189
raise TypeError(f"key must be an instance of str, not {type(key)}")
3190-
cmd = {"distinct": self._name, "key": key}
31913190
if filter is not None:
31923191
if "query" in kwargs:
31933192
raise ConfigurationError("can't pass both filter and query")
31943193
kwargs["query"] = filter
31953194
collation = validate_collation_or_none(kwargs.pop("collation", None))
3196-
cmd.update(kwargs)
3197-
if comment is not None:
3198-
cmd["comment"] = comment
31993195
if hint is not None:
32003196
if not isinstance(hint, str):
32013197
hint = helpers_shared._index_document(hint)
3202-
cmd["hint"] = hint # type: ignore[assignment]
32033198

32043199
def _cmd(
32053200
session: Optional[ClientSession],
32063201
_server: Server,
32073202
conn: Connection,
32083203
read_preference: Optional[_ServerMode],
32093204
) -> list: # type: ignore[type-arg]
3205+
cmd = {"distinct": self._name, "key": key}
3206+
cmd.update(kwargs)
3207+
if comment is not None:
3208+
cmd["comment"] = comment
3209+
if hint is not None:
3210+
cmd["hint"] = hint # type: ignore[assignment]
32103211
return (
32113212
self._command(
32123213
conn,
@@ -3241,27 +3242,26 @@ def _find_and_modify(
32413242
f"return_document must be ReturnDocument.BEFORE or ReturnDocument.AFTER, not {type(return_document)}"
32423243
)
32433244
collation = validate_collation_or_none(kwargs.pop("collation", None))
3244-
cmd = {"findAndModify": self._name, "query": filter, "new": return_document}
3245-
if let is not None:
3246-
common.validate_is_mapping("let", let)
3247-
cmd["let"] = let
3248-
cmd.update(kwargs)
3249-
if projection is not None:
3250-
cmd["fields"] = helpers_shared._fields_list_to_dict(projection, "projection")
3251-
if sort is not None:
3252-
cmd["sort"] = helpers_shared._index_document(sort)
3253-
if upsert is not None:
3254-
validate_boolean("upsert", upsert)
3255-
cmd["upsert"] = upsert
32563245
if hint is not None:
32573246
if not isinstance(hint, str):
32583247
hint = helpers_shared._index_document(hint)
3259-
3260-
write_concern = self._write_concern_for_cmd(cmd, session)
3248+
write_concern = self._write_concern_for_cmd(kwargs, session)
32613249

32623250
def _find_and_modify_helper(
32633251
session: Optional[ClientSession], conn: Connection, retryable_write: bool
32643252
) -> Any:
3253+
cmd = {"findAndModify": self._name, "query": filter, "new": return_document}
3254+
if let is not None:
3255+
common.validate_is_mapping("let", let)
3256+
cmd["let"] = let
3257+
cmd.update(kwargs)
3258+
if projection is not None:
3259+
cmd["fields"] = helpers_shared._fields_list_to_dict(projection, "projection")
3260+
if sort is not None:
3261+
cmd["sort"] = helpers_shared._index_document(sort)
3262+
if upsert is not None:
3263+
validate_boolean("upsert", upsert)
3264+
cmd["upsert"] = upsert
32653265
acknowledged = write_concern.acknowledged
32663266
if array_filters is not None:
32673267
if not acknowledged:

0 commit comments

Comments
 (0)