CSHARP-5994: Remove ReplaceOptions and UpdateOptions in favor of ReplaceOptions<T> and UpdateOptions<T> - #2078
Merged
Merged
Conversation
sanych-sun
requested review from
adelinowona and
ajcvickers
and removed request for
ajcvickers
July 20, 2026 18:26
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the driver’s update/replace option types and related CRUD APIs to remove the non-generic ReplaceOptions / UpdateOptions in favor of generic ReplaceOptions<T> / UpdateOptions<T>, and adjusts tests accordingly.
Changes:
- Refactors
UpdateOptionsandReplaceOptionsinto sealed generic types (UpdateOptions<T>,ReplaceOptions<T>) and updates conversion helpers. - Updates
IMongoCollection<TDocument>,MongoCollectionBase, andIMongoCollectionExtensionsmethod signatures to use the new generic options. - Updates driver test suite call sites to compile against the new options types.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedUpdateOneOperation.cs | Updates unified test operation to use UpdateOptions<BsonDocument>. |
| tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedUpdateManyOperation.cs | Updates unified test operation parsing/building to use UpdateOptions<BsonDocument>. |
| tests/MongoDB.Driver.Tests/OfTypeMongoCollectionTests.cs | Updates UpdateOptions construction to UpdateOptions<T>. |
| tests/MongoDB.Driver.Tests/MongoCollectionImplTests.cs | Updates replace/update options test coverage to ReplaceOptions<T> / UpdateOptions<T>. |
| tests/MongoDB.Driver.Tests/Linq/Integration/ReplaceOneUpsertedIdTests.cs | Updates replace options usage to ReplaceOptions<T>. |
| tests/MongoDB.Driver.Tests/Linq/Integration/PipelineUpdateWithToListTests.cs | Updates update-many options usage to UpdateOptions<T>. |
| tests/MongoDB.Driver.Tests/Linq/Integration/PipelineUpdateConditionalNestedObjectTests.cs | Updates update-many options usage to UpdateOptions<T>. |
| tests/MongoDB.Driver.Tests/JsonDrivenTests/JsonDrivenUpdateOneTest.cs | Updates stored options field to UpdateOptions<BsonDocument>. |
| tests/MongoDB.Driver.Tests/JsonDrivenTests/JsonDrivenUpdateManyTest.cs | Updates stored options field to UpdateOptions<BsonDocument>. |
| tests/MongoDB.Driver.Tests/JsonDrivenTests/JsonDrivenReplaceOneTest.cs | Updates stored options field to ReplaceOptions<BsonDocument>. |
| tests/MongoDB.Driver.Tests/IMongoCollectionExtensionsTests.cs | Updates mocks/verifications and options types to generic forms. |
| src/MongoDB.Driver/UpdateOptions.cs | Replaces the old non-generic + derived generic pattern with a single sealed UpdateOptions<T>. |
| src/MongoDB.Driver/ReplaceOptions.cs | Replaces the old non-generic + derived generic pattern with a single sealed ReplaceOptions<T> and updates From(...). |
| src/MongoDB.Driver/MongoCollectionBase.cs | Updates CRUD implementation signatures to accept the new generic options. |
| src/MongoDB.Driver/IMongoCollectionExtensions.cs | Updates extension method signatures to accept the new generic options. |
| src/MongoDB.Driver/IMongoCollection.cs | Updates public interface signatures to accept the new generic options. |
Comments suppressed due to low confidence (3)
src/MongoDB.Driver/ReplaceOptions.cs:51
ReplaceOptions<T>.From(UpdateOptions<T>)dropsComment(andSort) when converting options. This changes behavior for the obsolete ReplaceOne overload that acceptsUpdateOptions<T>and should preserve equivalent settings.
return new ReplaceOptions<T>
{
BypassDocumentValidation = updateOptions.BypassDocumentValidation,
Collation = updateOptions.Collation,
Hint = updateOptions.Hint,
src/MongoDB.Driver/MongoCollectionBase.cs:699
UpdateManynow acceptsUpdateOptions<TDocument>, which includesSort, but this method ignoresoptions.Sort. Consider throwing whenSortis set to avoid silently ignoring user input.
options ??= new UpdateOptions<TDocument>();
var model = new UpdateManyModel<TDocument>(filter, update)
{
ArrayFilters = options.ArrayFilters,
Collation = options.Collation,
src/MongoDB.Driver/MongoCollectionBase.cs:741
UpdateManyAsyncnow acceptsUpdateOptions<TDocument>, which includesSort, but this method ignoresoptions.Sort. Consider throwing whenSortis set to avoid silently ignoring user input.
options ??= new UpdateOptions<TDocument>();
var model = new UpdateManyModel<TDocument>(filter, update)
{
ArrayFilters = options.ArrayFilters,
Collation = options.Collation,
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+68
to
+72
| /// <summary> | ||
| /// Gets or sets the operation timeout. | ||
| /// </summary> | ||
| // TODO: CSOT: Make it public when CSOT will be ready for GA | ||
| internal TimeSpan? Timeout { get; set => field = Ensure.IsNullOrValidTimeout(value, nameof(Timeout)); } |
adelinowona
requested changes
Jul 22, 2026
adelinowona
approved these changes
Jul 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.