MongoDbRepositoryCore 3.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package MongoDbRepositoryCore --version 3.0.2
                    
NuGet\Install-Package MongoDbRepositoryCore -Version 3.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MongoDbRepositoryCore" Version="3.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MongoDbRepositoryCore" Version="3.0.2" />
                    
Directory.Packages.props
<PackageReference Include="MongoDbRepositoryCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MongoDbRepositoryCore --version 3.0.2
                    
#r "nuget: MongoDbRepositoryCore, 3.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MongoDbRepositoryCore@3.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MongoDbRepositoryCore&version=3.0.2
                    
Install as a Cake Addin
#tool nuget:?package=MongoDbRepositoryCore&version=3.0.2
                    
Install as a Cake Tool

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

  1. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed