Rig.TUnit.Databases.NoSql.Mongo
0.1.0-beta.2
dotnet add package Rig.TUnit.Databases.NoSql.Mongo --version 0.1.0-beta.2
NuGet\Install-Package Rig.TUnit.Databases.NoSql.Mongo -Version 0.1.0-beta.2
<PackageReference Include="Rig.TUnit.Databases.NoSql.Mongo" Version="0.1.0-beta.2" />
<PackageVersion Include="Rig.TUnit.Databases.NoSql.Mongo" Version="0.1.0-beta.2" />
<PackageReference Include="Rig.TUnit.Databases.NoSql.Mongo" />
paket add Rig.TUnit.Databases.NoSql.Mongo --version 0.1.0-beta.2
#r "nuget: Rig.TUnit.Databases.NoSql.Mongo, 0.1.0-beta.2"
#:package Rig.TUnit.Databases.NoSql.Mongo@0.1.0-beta.2
#addin nuget:?package=Rig.TUnit.Databases.NoSql.Mongo&version=0.1.0-beta.2&prerelease
#tool nuget:?package=Rig.TUnit.Databases.NoSql.Mongo&version=0.1.0-beta.2&prerelease
Rig.TUnit.Databases.NoSql.Mongo
Testcontainers-backed MongoDB fixture with
CollectionPerTestHelperandBsonDiff.
What this package is
The Rig.TUnit MongoDB provider. MongoFixture spins MongoDB via
Testcontainers and exposes an IMongoClient + default-database. Two
helpers solve the common pain points: CollectionPerTestHelper owns a
per-test collection scoped by IsolationKey and drops it on disposal,
and BsonDiff performs a structural diff between expected / actual
documents with the usual system-field scrub list.
When to use it
- Integration tests targeting MongoDB-specific features (change streams,
$lookup, text indexes, transactions with replica set). - Asserting document shape with tolerance for
_id/tsdrift. - Not for: unit tests — MongoDB's in-memory driver
Mongo2Gois faster but produces different wire errors from the real server.
Prerequisites
- .NET 10 SDK
- Docker Desktop / Colima (MongoDB image ~200 MB)
MongoDB.Driver3.x (transitive)
Quick start
using MongoDB.Bson;
using Rig.TUnit.Core.Helpers;
using Rig.TUnit.Databases.NoSql.Mongo.Fixtures;
using Rig.TUnit.Databases.NoSql.Mongo.Helpers;
await using var fx = new MongoFixture();
await fx.InitializeAsync();
await using var scope = new CollectionPerTestHelper(
fx.Database, IsolationKey.FromExecutionContext());
var orders = scope.GetCollection<BsonDocument>();
Options
| Property | Type | Default | Description |
|---|---|---|---|
Image |
string |
"mongo:7" |
Image |
StartupTimeoutSeconds |
int |
60 |
Mongo boots fast |
ReplicaSetName |
string? |
null |
Set for transactions; off by default |
AuthDatabase |
string? |
null |
Off by default in dev mode |
Fixture + helper APIs
Rig.TUnit.Databases.NoSql.Mongo.Fixtures.MongoFixtureRig.TUnit.Databases.NoSql.Mongo.Options.MongoFixtureOptionsRig.TUnit.Databases.NoSql.Mongo.Builder.MongoRigBuilderRig.TUnit.Databases.NoSql.Mongo.Helpers.CollectionPerTestHelperRig.TUnit.Databases.NoSql.Mongo.Assertions.BsonDiff
Per-test isolation
CollectionPerTestHelper names collections {logical}_{IsolationKey:short}
and calls Database.DropCollectionAsync on DisposeAsync. Fully
parallel-safe.
Parallelism + performance
- First-run pull: ~15 s.
- Warm startup: ~2 s.
- Per-test collection create + drop: ~30 ms.
- Parallelism: 8+ concurrent tests — collection-level isolation works well.
Troubleshooting
- Transactions fail with
Standalone servers do not support— setReplicaSetName = "rs0"; the fixture wires the replicaset init script. BsonDiffreports diff on_id— default scrub list includes_id,_etag,_ts. If your domain exposes a domain-levelIdalongside_id, scrub it too.
See docs/troubleshooting.md#mongo.
Provider quirks + edge cases
- MongoDB's default write-concern is
w: 1(acknowledged by primary) — tests asserting durability across a restart must usew: "majority". - Index creation is synchronous for small data, async for large. Test helpers assume small.
- Driver 3.x uses
MongoClientwhich is thread-safe; do not wrap inusing— dispose is process-level.
Benchmarks
See MongoBenchmarks.cs;
baseline in benchmarks/baseline-005.json.
Related docs
License
MIT. See LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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
- Bogus (>= 35.6.1)
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.0)
- MongoDB.Driver (>= 3.0.0)
- Rig.TUnit.Databases.NoSql (>= 0.1.0-beta.2)
- Testcontainers (>= 4.11.0)
- Testcontainers.MongoDb (>= 4.11.0)
- TUnit.Core (>= 1.34.5)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Rig.TUnit.Databases.NoSql.Mongo:
| Package | Downloads |
|---|---|
|
Rig.TUnit.All
Meta-package containing every Rig.TUnit.* package. DISCOURAGED — prefer per-feature or per-stack meta-packages (Rig.TUnit, Rig.TUnit.Microservices). |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0-beta.2 | 45 | 4/27/2026 |
| 0.0.0-alpha.0.14 | 60 | 4/26/2026 |