Tharga.MongoDB 2.10.9

dotnet add package Tharga.MongoDB --version 2.10.9
                    
NuGet\Install-Package Tharga.MongoDB -Version 2.10.9
                    
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="Tharga.MongoDB" Version="2.10.9" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tharga.MongoDB" Version="2.10.9" />
                    
Directory.Packages.props
<PackageReference Include="Tharga.MongoDB" />
                    
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 Tharga.MongoDB --version 2.10.9
                    
#r "nuget: Tharga.MongoDB, 2.10.9"
                    
#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 Tharga.MongoDB@2.10.9
                    
#: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=Tharga.MongoDB&version=2.10.9
                    
Install as a Cake Addin
#tool nuget:?package=Tharga.MongoDB&version=2.10.9
                    
Install as a Cake Tool

Tharga.MongoDB

A MongoDB repository toolkit for .NET 8 / 9 / 10. Adds dynamic database/collection naming, automatic index assurance, document-level locking with commit-on-success semantics, multi-document transactions, keyset pagination, and built-in monitoring of every call (latency, slow queries, cache stats) on top of the official MongoDB.Driver.

Install

dotnet add package Tharga.MongoDB
builder.AddMongoDB();

Configure connection strings in appsettings.json:

"ConnectionStrings": {
  "Default": "mongodb://localhost:27017/MyApp{Environment}{Part}"
}

Define an entity and a repository collection — both get auto-registered into DI:

public record Order : EntityBase<ObjectId>
{
    public string CustomerName { get; init; }
    public DateTime CreatedAt { get; init; }
}

public class OrderCollection : DiskRepositoryCollectionBase<Order, ObjectId>
{
    public OrderCollection(IMongoDbServiceFactory factory) : base(factory) { }
    public override string CollectionName => "orders";
}

Inject IRepositoryCollection<Order, ObjectId> (or your concrete collection) wherever you need it.

What's in the box

  • Repository pattern with Disk and Lockable collection bases. Lockable adds per-document optimistic locks with commit/release/error workflows so you can hand a document to a worker, let it crash, and have the lock auto-recover.
  • Dynamic database & collection naming via DatabaseContext — multi-tenant URLs like mongodb://.../{Environment}{Part} resolve at call time, not at startup.
  • Automatic index assurance with rename-safe modes (ByName, BySchema, DropCreate).
  • Multi-document transactions via WithTransactionAsync — session-aware writes on both Disk and Lockable; lockable leases support transactional commit so the document update and your business writes land atomically.
  • Keyset paginationGetPageAsync / GetPageProjectionAsync with opaque CursorToken. O(log N) per page regardless of depth, no skip penalty. CursorPager<TEntity, TKey> adapter for grids that emit (skip, pageSize).
  • Monitoring — every call (with filter, sort, explain plan) is captured and exposed via IDatabaseMonitor for live dashboards. Slow-query detection, queue metrics, cache stats, and per-collection status.
  • Result limiter — hard cap on returned document counts via ResultLimit config.
  • Execute limiter — auto-sized per connection pool to keep long-running streams from oversubscribing the driver.
  • Companion packages: Tharga.MongoDB.Blazor for the admin UI, Tharga.MongoDB.Mcp for MCP/AI integration, Tharga.MongoDB.Monitor.Client + .Server for centralised monitoring across multiple agents.

Documentation

Full docs, configuration reference, and worked examples for each feature: github.com/Tharga/MongoDB.

GitHub repo

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  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 (7)

Showing the top 5 NuGet packages that depend on Tharga.MongoDB:

Package Downloads
Tharga.MongoDB.Blazor

Drop-in Blazor admin UI for Tharga.MongoDB — Razor components that render the live monitoring data (collections, calls, indexes, queue metrics, connected clients) on any admin page.

Tharga.Cache.MongoDB

MongoDB cache features.

Tharga.Team.MongoDB

MontoDB Team features for Tharga Blazor.

Tharga.Team.Service

Server-side API-key authentication, authorization enforcement, controller registration, OpenAPI/Swagger setup, and audit logging for ASP.NET Core projects.

Tharga.MongoDB.Monitor.Client

Forwards MongoDB monitoring data to a central server via Tharga.Communication.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.10.9 0 5/5/2026
2.10.8 24 5/5/2026 2.10.8 is deprecated because it has critical bugs.
2.10.7 51 5/5/2026 2.10.7 is deprecated because it has critical bugs.
2.10.6 93 5/3/2026
2.10.5 327 4/29/2026
2.10.4 283 4/20/2026
2.10.3 310 4/16/2026
2.10.2 230 4/8/2026
2.10.1 356 4/5/2026
2.10.0 317 4/3/2026
2.9.1 190 3/28/2026
2.9.0 186 3/25/2026
2.8.5-pre.20 197 3/11/2026
2.8.5-pre.19 99 3/6/2026
2.8.5-pre.18 54 3/5/2026
2.8.5-pre.16 68 3/1/2026
2.8.5-pre.15 78 2/28/2026
2.8.5-pre.14 76 2/26/2026
2.8.2 109 3/24/2026
2.8.2-pre.1 52 3/24/2026
Loading failed