MongoDbRepositoryCore 3.2.0
See the version list below for details.
dotnet add package MongoDbRepositoryCore --version 3.2.0
NuGet\Install-Package MongoDbRepositoryCore -Version 3.2.0
<PackageReference Include="MongoDbRepositoryCore" Version="3.2.0" />
<PackageVersion Include="MongoDbRepositoryCore" Version="3.2.0" />
<PackageReference Include="MongoDbRepositoryCore" />
paket add MongoDbRepositoryCore --version 3.2.0
#r "nuget: MongoDbRepositoryCore, 3.2.0"
#:package MongoDbRepositoryCore@3.2.0
#addin nuget:?package=MongoDbRepositoryCore&version=3.2.0
#tool nuget:?package=MongoDbRepositoryCore&version=3.2.0
MongoDbRepository (v3.0) A robust, enterprise-grade, and async-first MongoDB Repository pattern implementation for .NET.
Designed for high performance and excellent Developer Experience (DX), Version 3 brings smart caching, fluent partial updates, cursor pagination, automated auditing, and multi-tenancy support right out of the box.
🚀 What's New in V3? Fluent Dependency Injection: One-liner setup for clients, databases, and repositories.
Smart Caching: Built-in caching decorator that safely and instantly evicts stale data during bulk updates and upserts.
Partial Updates & Upserts: Update specific fields safely using fluent lambda expressions without replacing entire documents.
O(1) Keyset Pagination: High-performance cursor-based pagination that won't degrade your database like Skip() and Limit().
Auto-Auditing & Soft Deletes: Implement IAuditableEntity or ISoftDeletable and let the repository handle your timestamps and data-hiding automatically.
Global Query Filters: Perfect for SaaS and multi-tenant applications.
Production Ready: Built-in support for OpenTelemetry (ActivitySource) and ASP.NET Core Health Checks.
📦 Installation Install via NuGet Package Manager:
Bash dotnet add package MongoDbRepositoryCore --version 3.0.0 🛠️ Getting Started
- Define your Entity Implement IEntity<TId>. You can also opt into automated features by adding IAuditableEntity and ISoftDeletable.
C# [BsonCollection("users")] public class User : IEntity<Guid>, IAuditableEntity, ISoftDeletable { public Guid Id { get; set; } = Guid.NewGuid(); public string Name { get; set; } public string Email { get; set; } public int LoginCount { get; set; }
// Auto-managed by the repository
public DateTime CreatedAt { get; set; }
public DateTime? UpdatedAt { get; set; }
public bool IsDeleted { get; set; }
public DateTime? DeletedAt { get; set; }
} 2. Register via Fluent DI (Program.cs) Forget manually wiring up MongoClient and settings. Use the new fluent builder:
C# builder.Services.AddMongoDbRepositories(db ⇒ { db.ConnectionString = builder.Configuration.GetConnectionString("MongoDb"); db.DatabaseName = "MyApplicationDb"; }, cache ⇒ { cache.SlidingExpirationMinutes = 5; }) .AddRepository<LogEntry, ObjectId>() // Standard direct-to-db repository .AddCachedRepository<User, Guid>() // Wrapped in a smart MemoryCache decorator .AddHealthCheck(); // Registers ASP.NET Core Health Checks 🔥 Key Features & Examples Fluent Partial Updates & Upserts Stop fetching entire documents just to update a single field. Use native, atomic MongoDB operators directly from C#:
C# // Atomic update of specific fields await _userRepo.UpdateFieldsAsync(userId, u ⇒ u .Set(x ⇒ x.Name, "New Name") .Inc(x ⇒ x.LoginCount, 1));
// Safe Upserts: Update if exists, or insert with default values await _userRepo.UpsertFieldsAsync(userId, updateAction: u ⇒ u.Set(x ⇒ x.LastLogin, DateTime.UtcNow), setOnInsertAction: i ⇒ i.Set(x ⇒ x.Email, "new@user.com") // Only runs on creation ); High-Performance Keyset Pagination For large datasets, Skip() is a performance killer. Use our built-in cursor pagination:
C# // Fetch the first page var firstPage = await _userRepo.GetCursorPagedAsync(x ⇒ x.IsActive, limit: 50);
// Fetch the next page using the cursor (LastId) from the previous result var nextPage = await _userRepo.GetCursorPagedAsync(x ⇒ x.IsActive, limit: 50, lastId: firstPage.LastId); Global Query Filters (Multi-Tenancy) Never accidentally leak cross-tenant data again. Implement IGlobalFilter<T> to automatically append filters to every read, update, and delete operation.
C# public class TenantFilter<T> : IGlobalFilter<T> where T : ITenantEntity { private readonly ITenantService _tenantService;
public TenantFilter(ITenantService tenantService) => _tenantService = tenantService;
public Expression<Func<T, bool>> GetFilter()
{
var tenantId = _tenantService.GetCurrentTenantId();
return entity => entity.TenantId == tenantId;
}
}
// Register it in DI: builder.Services.AddScoped(typeof(IGlobalFilter<>), typeof(TenantFilter<>)); Distributed Tracing (OpenTelemetry) Version 3 emits rich telemetry data natively. Just subscribe to the repository's ActivitySource in your OpenTelemetry setup:
C# builder.Services.AddOpenTelemetry() .WithTracing(tracing ⇒ tracing .AddSource("MongoDbRepository") // ← Subscribe to repository traces .AddAspNetCoreInstrumentation() .AddJaegerExporter()); 🗑️ Deleting Data Soft Deletes: Calling await repo.DeleteAsync(id) on an entity implementing ISoftDeletable will set IsDeleted = true. It will automatically be hidden from all future GetManyAsync queries.
Hard Deletes: To permanently wipe a document (e.g., GDPR compliance), bypass the soft delete via the escape hatch: await repo.HardDeleteAsync(id).
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Caching.Memory (>= 10.0.3)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.3)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.3)
- MongoDB.Driver (>= 3.6.0)
-
net9.0
- Microsoft.Extensions.Caching.Memory (>= 9.0.13)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 9.0.13)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.13)
- MongoDB.Driver (>= 3.6.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 5.0.4 | 102 | 5/14/2026 |
| 5.0.3 | 94 | 4/30/2026 |
| 5.0.2 | 96 | 4/25/2026 |
| 5.0.1 | 89 | 4/23/2026 |
| 5.0.0 | 109 | 4/21/2026 |
| 4.5.10 | 108 | 4/13/2026 |
| 4.5.4 | 102 | 4/10/2026 |
| 4.5.3 | 95 | 4/9/2026 |
| 4.5.2 | 96 | 4/9/2026 |
| 4.5.1 | 99 | 4/9/2026 |
| 4.1.0 | 100 | 4/9/2026 |
| 4.0.0 | 109 | 3/25/2026 |
| 3.4.5 | 112 | 3/20/2026 |
| 3.4.0 | 100 | 3/20/2026 |
| 3.3.0 | 109 | 3/20/2026 |
| 3.2.2 | 111 | 3/15/2026 |
| 3.2.1 | 107 | 3/15/2026 |
| 3.2.0 | 111 | 3/14/2026 |
| 3.1.0 | 108 | 3/6/2026 |
| 3.0.2 | 111 | 3/1/2026 |