Skip to content

CSHARP-5994: Remove ReplaceOptions and UpdateOptions in favor of ReplaceOptions<T> and UpdateOptions<T> - #2078

Merged
sanych-sun merged 4 commits into
mongodb:mainfrom
sanych-sun:CSHARP-5994
Jul 24, 2026
Merged

CSHARP-5994: Remove ReplaceOptions and UpdateOptions in favor of ReplaceOptions<T> and UpdateOptions<T>#2078
sanych-sun merged 4 commits into
mongodb:mainfrom
sanych-sun:CSHARP-5994

Conversation

@sanych-sun

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings July 20, 2026 18:26
@sanych-sun
sanych-sun requested a review from a team as a code owner July 20, 2026 18:26
@sanych-sun
sanych-sun requested review from adelinowona and ajcvickers and removed request for ajcvickers July 20, 2026 18:26
@sanych-sun sanych-sun added the improvement Optimizations or refactoring (no new features or fixes). label Jul 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 UpdateOptions and ReplaceOptions into sealed generic types (UpdateOptions<T>, ReplaceOptions<T>) and updates conversion helpers.
  • Updates IMongoCollection<TDocument>, MongoCollectionBase, and IMongoCollectionExtensions method 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>) drops Comment (and Sort) when converting options. This changes behavior for the obsolete ReplaceOne overload that accepts UpdateOptions<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

  • UpdateMany now accepts UpdateOptions<TDocument>, which includes Sort, but this method ignores options.Sort. Consider throwing when Sort is 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

  • UpdateManyAsync now accepts UpdateOptions<TDocument>, which includes Sort, but this method ignores options.Sort. Consider throwing when Sort is 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)); }
Comment thread src/MongoDB.Driver/ReplaceOptions.cs Outdated
Comment thread src/MongoDB.Driver/MongoCollectionBase.cs Outdated
Comment thread src/MongoDB.Driver/MongoCollectionBase.cs
Comment thread src/MongoDB.Driver/MongoCollectionBase.cs
@sanych-sun
sanych-sun requested a review from adelinowona July 23, 2026 20:03
@sanych-sun
sanych-sun merged commit 6cdfc72 into mongodb:main Jul 24, 2026
20 of 28 checks passed
@sanych-sun
sanych-sun deleted the CSHARP-5994 branch July 24, 2026 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Optimizations or refactoring (no new features or fixes).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants