Skip to content

Upgrade MongoDB.Driver to 3.1.0. #21807

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

Merged
merged 17 commits into from
Jan 23, 2025
Merged

Upgrade MongoDB.Driver to 3.1.0. #21807

merged 17 commits into from
Jan 23, 2025

Conversation

maliming
Copy link
Member

@maliming maliming commented Jan 3, 2025

Resolve #21491

Migration guide: https://github.com/abpframework/abp/blob/MongoDB.Driver.3/docs/en/release-info/migration-guides/MongoDB-Driver-2-to-3.md

MongoDB.Driver 3.x:

  • Async/Await Support: Write non-blocking, asynchronous code easily.
  • Fluent API: Build queries and updates intuitively with Builders.
  • LINQ Support: Use LINQ for querying MongoDB collections.
  • Enhanced Aggregation Framework: Simplified API for aggregation pipelines.
  • Strongly-Typed Classes: Interact with POCOs instead of BsonDocument.
  • Connection Pooling: Optimized for better performance and configurability.
  • Unified CRUD API: Consistent methods like InsertOneAsync, FindAsync, etc.
  • Transaction Support: ACID transactions for MongoDB 4.0+.
  • Improved Error Handling: Granular exceptions for better debugging.
  • GridFS Enhancements: Efficient APIs for large file storage and retrieval.

https://www.mongodb.com/docs/drivers/csharp/current/upgrade/v3/

@maliming maliming added this to the 9.2-preview milestone Jan 3, 2025
@maliming maliming marked this pull request as draft January 3, 2025 09:53
@maliming maliming marked this pull request as ready for review January 6, 2025 08:54
@maliming maliming requested a review from hikalkan January 13, 2025 09:16
@hikalkan
Copy link
Member

Thanks for the upgrade.

What are the breaking changes in that PR and how developers should apply these changes in their codebases?

@maliming
Copy link
Member Author

maliming commented Jan 17, 2025

@hikalkan
Copy link
Member

@maliming Can't we preserve GetMongoQueryableAsync method (and GetMongoQueryable) for backward compatilibity? We can make them obsolete and remove in v10.0. Because, we don't like to introduce such breaking changes in minor/feature versions.

@maliming
Copy link
Member Author

Can't we preserve GetMongoQueryableAsync method (and GetMongoQueryable) for backward compatilibity?

No problem. I have changed the code. You can review it again. Thanks


Task<IMongoQueryable<TEntity>> GetMongoQueryableAsync(CancellationToken cancellationToken = default, AggregateOptions? options = null);
[Obsolete("Use GetQueryableAsync method.")]
Task<IQueryable<TEntity>> GetMongoQueryableAsync(CancellationToken cancellationToken = default, AggregateOptions? options = null);
Copy link
Member

Choose a reason for hiding this comment

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

You are changing return value from IMongoQueryable to IQueryable, which is a breaking change for existing applications. Just keep as current, without any change, and mark it as obsolete (you already did this one).

Copy link
Member Author

Choose a reason for hiding this comment

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

The IMongoQueryable is deleted from MongoDB.Driver library.

[Obsolete("Use GetMongoQueryableAsync method.")]
public static IMongoQueryable<TEntity> GetMongoQueryable<TEntity>(this IReadOnlyBasicRepository<TEntity> repository)
[Obsolete("Use GetQueryableAsync method.")]
public static IQueryable<TEntity> GetMongoQueryable<TEntity>(this IReadOnlyBasicRepository<TEntity> repository)
Copy link
Member

Choose a reason for hiding this comment

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

Don't change return value.

Copy link
Member Author

Choose a reason for hiding this comment

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

The IMongoQueryable is deleted from MongoDB.Driver library.

where TEntity : class, IEntity
{
return repository.ToMongoDbRepository().GetMongoQueryable();
}

public static Task<IMongoQueryable<TEntity>> GetMongoQueryableAsync<TEntity>(this IReadOnlyBasicRepository<TEntity> repository, CancellationToken cancellationToken = default, AggregateOptions? aggregateOptions = null)
[Obsolete("Use GetQueryableAsync method.")]
public static Task<IQueryable<TEntity>> GetMongoQueryableAsync<TEntity>(this IReadOnlyBasicRepository<TEntity> repository, CancellationToken cancellationToken = default, AggregateOptions? aggregateOptions = null)
Copy link
Member

Choose a reason for hiding this comment

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

Don't change return value.

Copy link
Member Author

Choose a reason for hiding this comment

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

The IMongoQueryable is deleted from MongoDB.Driver library.

where TEntity : class, IEntity
{
return repository.ToMongoDbRepository().GetMongoQueryableAsync(cancellationToken, aggregateOptions);
}

[Obsolete("Use GetQueryableAsync method.")]
public static IQueryable<TEntity> GetQueryable<TEntity>(this IReadOnlyBasicRepository<TEntity> repository)
Copy link
Member

Choose a reason for hiding this comment

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

It is not necessary to add a new method and making it obsolete. It is against obsolete's purpose. Just don't add such a method, no one already used it yet, so it is not a breaking change.

Copy link
Member

@hikalkan hikalkan left a comment

Choose a reason for hiding this comment

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

Please read my previous change comments

@hikalkan hikalkan merged commit 25d70e2 into dev Jan 23, 2025
3 checks passed
@hikalkan hikalkan deleted the MongoDB.Driver.3 branch January 23, 2025 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MongoDBRepository not working in .NET 9 with MongoDB.Driver (3.0.0)
2 participants