A high-fidelity, in-process fake for the MongoDB .NET/C# Driver — zero Docker, zero network, instant startup.
- Instant — ~0ms startup (vs 2-15s for Docker/Mongo2Go)
- Portable — No Docker, no
mongodbinaries, no ports - Reliable — No flaky timeouts, port conflicts, or container failures
- High-fidelity — Real filter, update, and aggregation semantics (not mocks)
dotnet add package InMemoryEmulator.MongoDB # for MongoDB.Driver 3.x
dotnet add package InMemoryEmulator.MongoDB.V2Driver # for MongoDB.Driver 2.x
var result = InMemoryMongo.Create<Order>("orders");
var collection = result.Collection;
await collection.InsertOneAsync(new Order { Total = 99.99m });
var found = await collection.Find(o => o.Total > 50).FirstOrDefaultAsync();services.UseInMemoryMongoDB(options =>
{
options.DatabaseName = "testdb";
options.AddCollection<Order>("orders");
});| Feature | Status |
|---|---|
| Full CRUD (Insert, Find, Update, Replace, Delete, BulkWrite) | ✅ |
| Aggregation Pipeline (34 stages, 100+ expression operators) | ✅ |
| Indexes (Unique, Compound, Sparse, Partial Filter, TTL) | ✅ |
| Change Streams | ✅ |
| Transactions (snapshot isolation) | ✅ |
| GridFS | ✅ |
Schema Validation ($jsonSchema) |
✅ |
| Capped Collections + Tailable Cursors | ✅ |
| Views | ✅ |
LINQ (AsQueryable()) |
✅ |
| Fault Injection | ✅ |
| State Persistence (Export/Import) | ✅ |
| DI Integration (2 extension methods) | ✅ |
Both packages share the same namespace (
InMemoryEmulator.MongoDB) and feature set. Pick the one matching your driver version — the API is identical.
See the Wiki for full documentation:
- Getting Started
- Setup Guide (5 DI patterns)
- Features
- Filter & Update Operators
- Aggregation Pipeline (34 stages)
- Migration Guide (from Mongo2Go / Testcontainers)
- Known Limitations
- .NET 8.0+
InMemoryEmulator.MongoDBrequires MongoDB.Driver 3.x (tested up to 3.8.1)InMemoryEmulator.MongoDB.V2Driverrequires MongoDB.Driver 2.x (tested up to 2.30.0)