-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow updateOne and replaceOne to supply sort option #1585
base: main
Are you sure you want to change the base?
Changes from all commits
100910d
d51fa83
19c77f3
fc7ec3e
445b15d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -40,6 +40,7 @@ public class UpdateOptions { | |||||||||||
private String hintString; | ||||||||||||
private BsonValue comment; | ||||||||||||
private Bson variables; | ||||||||||||
private Bson sort; | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Returns true if a new document should be inserted if there are no matches to the query filter. The default is false. | ||||||||||||
|
@@ -256,6 +257,43 @@ public UpdateOptions let(final Bson variables) { | |||||||||||
return this; | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Gets the sort criteria to apply to the operation. | ||||||||||||
* | ||||||||||||
* <p> | ||||||||||||
* The sort criteria determines which document the operation updates if the query matches multiple documents. | ||||||||||||
* The first document matched by the sort criteria will be updated. | ||||||||||||
* The default is null, which means no specific sort criteria is applied. | ||||||||||||
* | ||||||||||||
* @return a document describing the sort criteria, or null if no sort is specified. | ||||||||||||
* @mongodb.driver.manual reference/method/db.collection.updateOne/ Sort | ||||||||||||
* @mongodb.server.release 8.0 | ||||||||||||
* @since 5.3 | ||||||||||||
* @see #sort(Bson) | ||||||||||||
*/ | ||||||||||||
@Nullable | ||||||||||||
public Bson getSort() { | ||||||||||||
return sort; | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Sets the sort criteria to apply to the operation. A null value means no sort criteria is set. | ||||||||||||
* | ||||||||||||
* <p> | ||||||||||||
* The sort criteria determines which document the operation updates if the query matches multiple documents. | ||||||||||||
* The first document matched by the specified sort criteria will be updated. | ||||||||||||
* | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we clarify the purpose of this sort option in the Javadoc? It would be helpful to explain how it determines which document is updated when multiple matches are found.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do! |
||||||||||||
* @param sort the sort criteria, which may be null. | ||||||||||||
* @return this | ||||||||||||
* @mongodb.driver.manual reference/method/db.collection.updateOne/ Sort | ||||||||||||
* @mongodb.server.release 8.0 | ||||||||||||
* @since 5.3 | ||||||||||||
*/ | ||||||||||||
public UpdateOptions sort(@Nullable final Bson sort) { | ||||||||||||
this.sort = sort; | ||||||||||||
return this; | ||||||||||||
} | ||||||||||||
|
||||||||||||
@Override | ||||||||||||
public String toString() { | ||||||||||||
return "UpdateOptions{" | ||||||||||||
|
@@ -267,6 +305,7 @@ public String toString() { | |||||||||||
+ ", hintString=" + hintString | ||||||||||||
+ ", comment=" + comment | ||||||||||||
+ ", let=" + variables | ||||||||||||
+ ", sort=" + sort | ||||||||||||
+ '}'; | ||||||||||||
} | ||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s also add unit tests to
UpdateOptionsSpecification
andUpdateRequestSpecification
.Additionally, we should update the tests in
MongoCollectionSpecification
to cover the logic for the new option.