Tharga.MongoDB
2.10.9
dotnet add package Tharga.MongoDB --version 2.10.9
NuGet\Install-Package Tharga.MongoDB -Version 2.10.9
<PackageReference Include="Tharga.MongoDB" Version="2.10.9" />
<PackageVersion Include="Tharga.MongoDB" Version="2.10.9" />
<PackageReference Include="Tharga.MongoDB" />
paket add Tharga.MongoDB --version 2.10.9
#r "nuget: Tharga.MongoDB, 2.10.9"
#:package Tharga.MongoDB@2.10.9
#addin nuget:?package=Tharga.MongoDB&version=2.10.9
#tool nuget:?package=Tharga.MongoDB&version=2.10.9
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
DiskandLockablecollection 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 likemongodb://.../{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 pagination —
GetPageAsync/GetPageProjectionAsyncwith opaqueCursorToken. 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
IDatabaseMonitorfor live dashboards. Slow-query detection, queue metrics, cache stats, and per-collection status. - Result limiter — hard cap on returned document counts via
ResultLimitconfig. - Execute limiter — auto-sized per connection pool to keep long-running streams from oversubscribing the driver.
- Companion packages:
Tharga.MongoDB.Blazorfor the admin UI,Tharga.MongoDB.Mcpfor MCP/AI integration,Tharga.MongoDB.Monitor.Client+.Serverfor centralised monitoring across multiple agents.
Documentation
Full docs, configuration reference, and worked examples for each feature: github.com/Tharga/MongoDB.
| Product | Versions 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. |
-
net10.0
- Microsoft.Extensions.Configuration.Binder (>= 10.0.7)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Features (>= 10.0.7)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Http (>= 10.0.7)
- MongoDB.Driver (>= 3.8.0)
- System.Linq.Async (>= 7.0.1)
- Tharga.Runtime (>= 0.1.11)
-
net8.0
- Microsoft.Extensions.Configuration.Binder (>= 10.0.7)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Features (>= 10.0.7)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Http (>= 10.0.7)
- MongoDB.Driver (>= 3.8.0)
- System.Linq.Async (>= 7.0.1)
- Tharga.Runtime (>= 0.1.11)
-
net9.0
- Microsoft.Extensions.Configuration.Binder (>= 10.0.7)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Features (>= 10.0.7)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Http (>= 10.0.7)
- MongoDB.Driver (>= 3.8.0)
- System.Linq.Async (>= 7.0.1)
- Tharga.Runtime (>= 0.1.11)
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.7 | 51 | 5/5/2026 | |
| 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 |