MongoDbRepositoryCore 3.3.0
See the version list below for details.
dotnet add package MongoDbRepositoryCore --version 3.3.0
NuGet\Install-Package MongoDbRepositoryCore -Version 3.3.0
<PackageReference Include="MongoDbRepositoryCore" Version="3.3.0" />
<PackageVersion Include="MongoDbRepositoryCore" Version="3.3.0" />
<PackageReference Include="MongoDbRepositoryCore" />
paket add MongoDbRepositoryCore --version 3.3.0
#r "nuget: MongoDbRepositoryCore, 3.3.0"
#:package MongoDbRepositoryCore@3.3.0
#addin nuget:?package=MongoDbRepositoryCore&version=3.3.0
#tool nuget:?package=MongoDbRepositoryCore&version=3.3.0
MongoDbRepository (v3.3.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.3.0 brings declarative data modeling, field-level encryption, network-optimized projections, and server-side math right out of the box.
🚀 What's New in V3.3.0? Declarative Data Modeling: Control your database directly from your C# entities using [AutoIndex], [UniqueIndex], [CompoundIndex], and [TextSearch].
Field-Level Encryption (FLE): Secure PII instantly by dropping a [SecureString] attribute on any property.
Auto-Auditing: The [UpdatedAt] attribute automatically syncs your modified timestamps with 0% CPU overhead.
Projections: Save massive amounts of RAM and network bandwidth using .GetProjectedManyAsync().
Server-Side Aggregations: Calculate .SumAsync(), .AverageAsync(), and .GetDistinctAsync() natively on the database server.
Global Guid Setup: Safely abstracts away MongoDB's BSON Guid Representation setup.
📦 Installation Install via NuGet Package Manager:
Bash dotnet add package MongoDbRepositoryCore --version 3.3.0 🛠️ Getting Started
- Define your Entity (The V3.3 Way) Implement IEntity<TId>. You can now opt into automated indexing, text searching, and field-level encryption using our powerful attribute engine!
C# [BsonCollection("users")] [CompoundIndex(nameof(Department), nameof(Role))] // Creates a background compound index public class User : IEntity<Guid>, IAuditableEntity, ISoftDeletable { public Guid Id { get; set; }
[TextSearch] // Adds this field to the global $text search index
public string Name { get; set; }
[UniqueIndex] // Ensures no duplicate emails ever enter the database
public string Email { get; set; }
[SecureString] // Encrypts the data in MongoDB, decrypts it in C#!
public string SocialSecurityNumber { get; set; }
public string Department { get; set; }
public string Role { get; set; }
public DateTime CreatedAt { get; set; }
[UpdatedAt] // Automatically updated to DateTime.UtcNow on every Upsert/Update!
public DateTime LastModified { get; set; }
public bool IsDeleted { get; set; }
public DateTime? DeletedAt { get; set; }
} 2. Register in Dependency Injection Setup is a simple, fluent one-liner. You can optionally configure legacy Guids and enable Field-Level encryption here:
C# builder.Services.AddMongoDbRepositories(db ⇒ { db.ConnectionString = "mongodb://localhost:27017"; db.DatabaseName = "MyApp"; }) .WithGuidRepresentation(GuidRepresentation.Standard) // V3.3: Abstracted & Thread-Safe .AddRepository<User, Guid>() .EnableFieldLevelEncryption("MySecureApp.Encryption"); // V3.3: Activates [SecureString] 🔥 High-Performance Features (New in 3.3.0) Projections (Network & RAM Optimization) Don't download a 5MB document just to read a user's name. Project directly into lightweight DTOs or anonymous types!
C# var lightweightUsers = await _userRepo.GetProjectedManyAsync( filter: u ⇒ u.IsActive, projection: u ⇒ new { u.Id, u.Name } // Leaves heavy data behind in the DB! ); Server-Side Aggregations & Math Let MongoDB do the heavy lifting. Crunch numbers across millions of rows instantly:
C# // Returns a single decimal (e.g. 150000.50) without downloading documents decimal totalBudget = await _projectRepo.SumAsync(p ⇒ p.IsActive, p ⇒ p.Budget);
// Get a unique list of strings for UI Dropdowns IEnumerable<string> uniqueRoles = await _userRepo.GetDistinctAsync(u ⇒ u.Role);
// Blazing fast existence checks (stops searching after 1 match) bool emailTaken = await _userRepo.ExistsAsync(u ⇒ u.Email == "test@test.com"); Global Full-Text Search Search across all properties marked with [TextSearch] simultaneously using Google-style stemming and relevance scoring:
C# // Searches Name, Description, and Tags simultaneously for the word "Server" var results = await _projectRepo.SearchTextAsync("Server", filter: p ⇒ p.IsActive); 🛡️ Enterprise Core Features 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<>)); O(1) Keyset Pagination High-performance cursor-based pagination that won't degrade your database like Skip() and Limit().
C# var firstPage = await repo.GetCursorPagedAsync(x ⇒ x.IsActive, limit: 50); var secondPage = await repo.GetCursorPagedAsync(x ⇒ x.IsActive, limit: 50, lastId: firstPage.LastId); Distributed Tracing (OpenTelemetry) Version 3 emits rich telemetry data natively. Every query tracks execution time, document counts, and specific MongoDB collections. 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.AspNetCore.DataProtection (>= 10.0.5)
- Microsoft.AspNetCore.DataProtection.Abstractions (>= 10.0.5)
- Microsoft.Extensions.Caching.Memory (>= 10.0.5)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.5)
- MongoDB.Driver (>= 3.7.0)
-
net9.0
- Microsoft.AspNetCore.DataProtection (>= 10.0.5)
- Microsoft.AspNetCore.DataProtection.Abstractions (>= 10.0.5)
- Microsoft.Extensions.Caching.Memory (>= 10.0.5)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.5)
- MongoDB.Driver (>= 3.7.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 |