Skip to content

Commit da8e120

Browse files
authored
DRIVERS-2822 Add sort option to updateOne (#1644)
1 parent 1de6a19 commit da8e120

14 files changed

+1889
-1
lines changed

source/crud/bulk-write.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ class UpdateOneModel implements WriteModel {
9090
* value is false.
9191
*/
9292
upsert: Optional<Boolean>;
93+
94+
/**
95+
* Specify which document the operation updates if the query matches multiple
96+
* documents. The first document matched by the sort order will be updated.
97+
*
98+
* This option is only sent if the caller explicitly provides a value.
99+
*/
100+
sort: Optional<Document>;
93101
}
94102

95103
class UpdateManyModel implements WriteModel {
@@ -167,6 +175,14 @@ class ReplaceOneModel implements WriteModel {
167175
* value is false.
168176
*/
169177
upsert: Optional<Boolean>;
178+
179+
/**
180+
* Specify which document the operation replaces if the query matches multiple
181+
* documents. The first document matched by the sort order will be replaced.
182+
*
183+
* This option is only sent if the caller explicitly provides a value.
184+
*/
185+
sort: Optional<Document>;
170186
}
171187

172188
class DeleteOneModel implements WriteModel {
@@ -909,6 +925,8 @@ batch-splitting to standardize implementations across drivers and simplify batch
909925

910926
## **Changelog**
911927

928+
- 2024-10-01: Add sort option to `replaceOne` and `updateOne`.
929+
912930
- 2024-09-30: Define more options for modeling summary vs. verbose results.
913931

914932
- 2024-09-25: Add `collation` field to `update` document and clarify usage of `updateMods`.

source/crud/crud.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,6 @@ class UpdateOptions {
10491049
*/
10501050
upsert: Optional<Boolean>;
10511051

1052-
10531052
/**
10541053
* Map of parameter names and values. Values must be constant or closed
10551054
* expressions that do not reference document fields. Parameters can then be
@@ -1071,6 +1070,18 @@ class UpdateOptions {
10711070
* and providing one will result in a server-side error.
10721071
*/
10731072
comment: Optional<any>;
1073+
1074+
/**
1075+
* Specify which document the operation updates if the query matches multiple
1076+
* documents. The first document matched by the sort order will be updated.
1077+
*
1078+
* This option is sent only if the caller explicitly provides a value. The default is to not send a value.
1079+
* The server will report an error if the caller explicitly provides a value with updateMany().
1080+
* This option is only supported by servers >= 8.0. Older servers will report an error for using this option.
1081+
*
1082+
* @see https://www.mongodb.com/docs/manual/reference/command/update/
1083+
*/
1084+
sort: Optional<Document>;
10741085
}
10751086

10761087
class ReplaceOptions {
@@ -1139,6 +1150,17 @@ class ReplaceOptions {
11391150
* and providing one will result in a server-side error.
11401151
*/
11411152
comment: Optional<any>;
1153+
1154+
/**
1155+
* Specify which document the operation replaces if the query matches multiple
1156+
* documents. The first document matched by the sort order will be replaced.
1157+
*
1158+
* This option is sent only if the caller explicitly provides a value. The default is to not send a value.
1159+
* This option is only supported by servers >= 8.0. Older servers will report an error for using this option.
1160+
*
1161+
* @see https://www.mongodb.com/docs/manual/reference/command/update/
1162+
*/
1163+
sort: Optional<Document>;
11421164
}
11431165

11441166
class DeleteOptions {
@@ -1319,6 +1341,17 @@ class ReplaceOneModel implements WriteModel {
13191341
*/
13201342
hint: Optional<(String | Document)>;
13211343

1344+
/**
1345+
* Specify which document the operation replaces if the query matches multiple
1346+
* documents. The first document matched by the sort order will be replaced.
1347+
*
1348+
* This option is sent only if the caller explicitly provides a value. The default is to not send a value.
1349+
* This option is only supported by servers >= 8.0. Older servers will report an error for using this option.
1350+
*
1351+
* @see https://www.mongodb.com/docs/manual/reference/command/update/
1352+
*/
1353+
sort: Optional<Document>;
1354+
13221355
/**
13231356
* When true, creates a new document if no document matches the query.
13241357
*
@@ -1381,6 +1414,17 @@ class UpdateOneModel implements WriteModel {
13811414
*/
13821415
hint: Optional<(String | Document)>;
13831416

1417+
/**
1418+
* Specify which document the operation updates if the query matches multiple
1419+
* documents. The first document matched by the sort order will be updated.
1420+
*
1421+
* This option is sent only if the caller explicitly provides a value. The default is to not send a value.
1422+
* This option is only supported by servers >= 8.0. Older servers will report an error for using this option.
1423+
*
1424+
* @see https://www.mongodb.com/docs/manual/reference/command/update/
1425+
*/
1426+
sort: Optional<Document>;
1427+
13841428
/**
13851429
* When true, creates a new document if no document matches the query.
13861430
*
@@ -2430,6 +2474,8 @@ aforementioned allowance in the SemVer spec.
24302474

24312475
## Changelog
24322476

2477+
- 2024-10-01: Add sort option to `replaceOne` and `updateOne`.
2478+
24332479
- 2024-09-12: Specify that explain helpers support maxTimeMS.
24342480

24352481
- 2024-02-20: Migrated from reStructuredText to Markdown.

source/crud/tests/unified/bulkWrite-replaceOne-sort.json

Lines changed: 239 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)