-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Aryeh Citron edited this page May 12, 2026
·
4 revisions
A high-fidelity, in-process fake for the MongoDB .NET/C# Driver — designed for fast, reliable integration and unit tests without Docker, Testcontainers, or Mongo2Go.
| Problem | Solution |
|---|---|
| Docker-based MongoDB is slow to start | In-memory, instant startup (~0ms) |
Mongo2Go downloads & manages mongod binaries |
Zero external dependencies |
| Testcontainers require Docker Desktop | Runs anywhere — CI, laptops, codespaces |
Mocking IMongoCollection<T> is tedious and fragile |
Drop-in replacement with real query semantics |
| Real MongoDB flakes on CI (timeouts, port conflicts) | Deterministic, no network, no ports |
dotnet add package InMemoryEmulator.MongoDB
var result = InMemoryMongo.Create<MyDocument>("myCollection");
var collection = result.Collection;
await collection.InsertOneAsync(new MyDocument { Name = "Test" });
var found = await collection.Find(x => x.Name == "Test").FirstOrDefaultAsync();// In your test's ConfigureTestServices:
services.UseInMemoryMongoDB(options =>
{
options.DatabaseName = "testdb";
options.AddCollection<MyDocument>("myCollection");
});- Full CRUD — Insert, Find, Update, Replace, Delete, Upsert, BulkWrite
- Aggregation Pipeline — 34 stages, 100+ expression operators
- Indexes — Unique (enforced), Compound, Sparse, Partial Filter, TTL with lazy eviction
- Change Streams — Collection, database, and client-level, with resume tokens
- Transactions — StartTransaction / Commit / Abort with snapshot isolation
- GridFS — Upload, download, find, rename, delete
-
Schema Validation —
$jsonSchemaenforcement on writes -
LINQ —
AsQueryable()with LINQ-to-Objects - Fault Injection — Simulate errors on any operation
- State Persistence — Export / Import JSON snapshots
See Features for the complete list.
- Getting Started: Getting Started · Unit Testing
- DI & Integration: How It Works · Setup Guide · Choosing Your Approach
- Reference: Features · Filter & Update Operators · Aggregation Pipeline · LINQ Support
- Help: Known Limitations · Troubleshooting · Migration Guide
Getting Started
Integration & Dependency Injection
Data Management
Reference
- Feature Comparison
- Features
- Filter & Update Operators
- Aggregation Pipeline
- LINQ Support
- API Reference
Help