MongoDbRepositoryCore 3.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package MongoDbRepositoryCore --version 3.4.0
                    
NuGet\Install-Package MongoDbRepositoryCore -Version 3.4.0
                    
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.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MongoDbRepositoryCore" Version="3.4.0" />
                    
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.4.0
                    
#r "nuget: MongoDbRepositoryCore, 3.4.0"
                    
#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.4.0
                    
#: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.4.0
                    
Install as a Cake Addin
#tool nuget:?package=MongoDbRepositoryCore&version=3.4.0
                    
Install as a Cake Tool

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

  1. 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 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 110 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 101 4/9/2026
4.0.0 110 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 112 3/14/2026
3.1.0 109 3/6/2026
3.0.2 111 3/1/2026
Loading failed