Skip to content

Repository files navigation

InMemoryEmulator.MongoDB icon InMemoryEmulator.MongoDB

NuGet License: MIT

A high-fidelity, in-process fake for the MongoDB .NET/C# Driver — zero Docker, zero network, instant startup.

Why?

  • Instant — ~0ms startup (vs 2-15s for Docker/Mongo2Go)
  • Portable — No Docker, no mongod binaries, no ports
  • Reliable — No flaky timeouts, port conflicts, or container failures
  • High-fidelity — Real filter, update, and aggregation semantics (not mocks)

Quick Start

dotnet add package InMemoryEmulator.MongoDB          # for MongoDB.Driver 3.x
dotnet add package InMemoryEmulator.MongoDB.V2Driver  # for MongoDB.Driver 2.x

Unit Tests

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();

Integration Tests (DI)

services.UseInMemoryMongoDB(options =>
{
    options.DatabaseName = "testdb";
    options.AddCollection<Order>("orders");
});

What's Supported

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) ✅

NuGet Packages

Package Description NuGet
InMemoryEmulator.MongoDB Core library for MongoDB.Driver 3.x NuGet Version
InMemoryEmulator.MongoDB.V2Driver Core library for MongoDB.Driver 2.x NuGet Version
InMemoryEmulator.MongoDB.JsTriggers $function, $accumulator, $where via Jint NuGet Version

Both packages share the same namespace (InMemoryEmulator.MongoDB) and feature set. Pick the one matching your driver version — the API is identical.

Documentation

See the Wiki for full documentation:

Requirements

  • .NET 8.0+
  • InMemoryEmulator.MongoDB requires MongoDB.Driver 3.x (tested up to 3.8.1)
  • InMemoryEmulator.MongoDB.V2Driver requires MongoDB.Driver 2.x (tested up to 2.30.0)

License

MIT

About

An In-Process Emulator/Fake For MongoDB To Be Used For Integration/Component Testing

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages