-
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 2 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
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. Let’s also add unit tests to Additionally, we should update the tests in |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -19,6 +19,7 @@ | |||||||||||
import com.mongodb.lang.Nullable; | ||||||||||||
import org.bson.BsonString; | ||||||||||||
import org.bson.BsonValue; | ||||||||||||
import org.bson.BsonDocument; | ||||||||||||
import org.bson.conversions.Bson; | ||||||||||||
|
||||||||||||
import java.util.List; | ||||||||||||
|
@@ -40,6 +41,7 @@ public class UpdateOptions { | |||||||||||
private String hintString; | ||||||||||||
private BsonValue comment; | ||||||||||||
private Bson variables; | ||||||||||||
private BsonDocument sort; | ||||||||||||
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. Let’s use the |
||||||||||||
|
||||||||||||
/** | ||||||||||||
* Returns true if a new document should be inserted if there are no matches to the query filter. The default is false. | ||||||||||||
|
@@ -256,6 +258,32 @@ public UpdateOptions let(final Bson variables) { | |||||||||||
return this; | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Gets the sort criteria to apply to the query. The default is null, which means that the documents will be returned in an undefined | ||||||||||||
* order. | ||||||||||||
* | ||||||||||||
* @return a document describing the sort criteria | ||||||||||||
* @since 5.3 | ||||||||||||
* @mongodb.driver.manual reference/method/cursor.sort/ Sort | ||||||||||||
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. Should we remove the manual reference here and from the 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. I referenced the |
||||||||||||
*/ | ||||||||||||
@Nullable | ||||||||||||
public BsonDocument getSort() { | ||||||||||||
return sort; | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Sets the sort criteria to apply to the query. | ||||||||||||
* | ||||||||||||
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 | ||||||||||||
* @since 5.3 | ||||||||||||
* @mongodb.driver.manual reference/method/cursor.sort/ Sort | ||||||||||||
*/ | ||||||||||||
public UpdateOptions sort(@Nullable final BsonDocument sort) { | ||||||||||||
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. Should we consider adding a note in the Javadoc to clarify that sort is not applicable to 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. This is a good point, will go ahead and add it! |
||||||||||||
this.sort = sort; | ||||||||||||
return this; | ||||||||||||
} | ||||||||||||
|
||||||||||||
@Override | ||||||||||||
public String toString() { | ||||||||||||
return "UpdateOptions{" | ||||||||||||
|
@@ -267,6 +295,7 @@ public String toString() { | |||||||||||
+ ", hintString=" + hintString | ||||||||||||
+ ", comment=" + comment | ||||||||||||
+ ", let=" + variables | ||||||||||||
+ ", sort=" + sort | ||||||||||||
+ '}'; | ||||||||||||
} | ||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,7 @@ public class MixedBulkWriteOperation implements AsyncWriteOperation<BulkWriteRes | |
private Boolean bypassDocumentValidation; | ||
private BsonValue comment; | ||
private BsonDocument variables; | ||
private BsonDocument sort; | ||
|
||
public MixedBulkWriteOperation(final MongoNamespace namespace, final List<? extends WriteRequest> writeRequests, | ||
final boolean ordered, final WriteConcern writeConcern, final boolean retryWrites) { | ||
|
@@ -130,6 +131,15 @@ public MixedBulkWriteOperation comment(@Nullable final BsonValue comment) { | |
return this; | ||
} | ||
|
||
public BsonDocument getSort() { | ||
return sort; | ||
} | ||
|
||
public MixedBulkWriteOperation sort(@Nullable final BsonDocument sort) { | ||
this.sort = sort; | ||
return this; | ||
} | ||
|
||
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. These methods don’t appear to be used. Should we consider removing them? This also applies to |
||
public MixedBulkWriteOperation let(@Nullable final BsonDocument variables) { | ||
this.variables = variables; | ||
return this; | ||
|
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.
Judging by the spec, BulkWriteOptions does not seem to require a sort option.
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.
I overlooked that part, will remove it!