Skip to content

Commit 14c2d80

Browse files
committed
address review
1 parent aa636d4 commit 14c2d80

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

doc/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ PyMongo 4.11 brings a number of changes including:
1919
until either connection succeeds or a server selection timeout error is raised.
2020
- Added :func:`repr` support to :class:`pymongo.operations.IndexModel`.
2121
- Added :func:`repr` support to :class:`pymongo.operations.SearchIndexModel`.
22+
- Added ``sort`` parameter to
23+
:meth:`~pymongo.collection.Collection.update_one` and :meth:`~pymongo.collection.Collection.replace_one`
2224

2325
Issues Resolved
2426
...............

pymongo/asynchronous/collection.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,9 +1190,10 @@ async def replace_one(
11901190
command.
11911191
:param sort: Specify which document the operation updates if the query matches
11921192
multiple documents. The first document matched by the sort order will be updated.
1193+
This option is only supported on MongoDB 8.0 and above.
11931194
:return: - An instance of :class:`~pymongo.results.UpdateResult`.
11941195
1195-
.. versionchanged:: 4.10
1196+
.. versionchanged:: 4.11
11961197
Added ``sort`` parameter.
11971198
.. versionchanged:: 4.1
11981199
Added ``let`` parameter.
@@ -1303,12 +1304,13 @@ async def update_one(
13031304
aggregate expression context (e.g. "$$var").
13041305
:param sort: Specify which document the operation updates if the query matches
13051306
multiple documents. The first document matched by the sort order will be updated.
1307+
This option is only supported on MongoDB 8.0 and above.
13061308
:param comment: A user-provided comment to attach to this
13071309
command.
13081310
13091311
:return: - An instance of :class:`~pymongo.results.UpdateResult`.
13101312
1311-
.. versionchanged:: 4.10
1313+
.. versionchanged:: 4.11
13121314
Added ``sort`` parameter.
13131315
.. versionchanged:: 4.1
13141316
Added ``let`` parameter.

pymongo/synchronous/collection.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,9 +1189,10 @@ def replace_one(
11891189
command.
11901190
:param sort: Specify which document the operation updates if the query matches
11911191
multiple documents. The first document matched by the sort order will be updated.
1192+
This option is only supported on MongoDB 8.0 and above.
11921193
:return: - An instance of :class:`~pymongo.results.UpdateResult`.
11931194
1194-
.. versionchanged:: 4.10
1195+
.. versionchanged:: 4.11
11951196
Added ``sort`` parameter.
11961197
.. versionchanged:: 4.1
11971198
Added ``let`` parameter.
@@ -1302,12 +1303,13 @@ def update_one(
13021303
aggregate expression context (e.g. "$$var").
13031304
:param sort: Specify which document the operation updates if the query matches
13041305
multiple documents. The first document matched by the sort order will be updated.
1306+
This option is only supported on MongoDB 8.0 and above.
13051307
:param comment: A user-provided comment to attach to this
13061308
command.
13071309
13081310
:return: - An instance of :class:`~pymongo.results.UpdateResult`.
13091311
1310-
.. versionchanged:: 4.10
1312+
.. versionchanged:: 4.11
13111313
Added ``sort`` parameter.
13121314
.. versionchanged:: 4.1
13131315
Added ``let`` parameter.

test/utils.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -958,11 +958,6 @@ def parse_spec_options(opts):
958958
def prepare_spec_arguments(spec, arguments, opname, entity_map, with_txn_callback):
959959
for arg_name in list(arguments):
960960
c2s = camel_to_snake(arg_name)
961-
# PyMongo accepts sort as list of tuples or as an optional dict for update/replaceOne.
962-
if arg_name == "sort":
963-
if spec["name"] not in ["replaceOne", "updateOne"]:
964-
sort_dict = arguments[arg_name]
965-
arguments[arg_name] = list(sort_dict.items())
966961
# Named "key" instead not fieldName.
967962
if arg_name == "fieldName":
968963
arguments["key"] = arguments.pop(arg_name)

0 commit comments

Comments
 (0)