Skip to content

Feature Comparison With Alternatives

aryehcitron@gmail.com edited this page May 25, 2026 · 5 revisions

Feature Comparison With Alternatives

Applies to: InMemoryEmulator.MongoDB v1.0.0+

vs Mongo2Go / Testcontainers / Real MongoDB

InMemory Emulator Mongo2Go Testcontainers.MongoDB Real MongoDB
Architecture In-process fake — implements IMongoClient/IMongoCollection<T> directly in C# Managed wrapper around real mongod binary (v4.4.4). Downloads and launches a child process on a random port Docker container running official MongoDB image. Managed via Testcontainers .NET library Full MongoDB server (standalone, replica set, or sharded cluster)
Install size ~NuGet package only (< 1 MB) ~200 MB (bundled mongod + mongoimport + mongoexport for Win/Linux/macOS) ~200–600 MB Docker image (depending on MongoDB version) ~300 MB+ server install
Typical startup time ~0 ms (object construction) 2–5 s (extract binaries + start mongod + wait for port) 5–15 s (Docker pull + container start + health check) N/A (always running)
Connection mode Direct in-memory method calls Real TCP connection (localhost) Real TCP connection (mapped Docker port) Real TCP/TLS connection
Supported MongoDB version behavior v5.0+ semantics (operator-level reimplementation) v4.4.4 (bundled binary; fixed) Any (choose Docker image tag) Any
Platform Any OS that runs .NET 8.0+ Windows, Linux, macOS (requires matching native binaries) Any OS with Docker Desktop or daemon Any supported platform
Status Active development (frequent releases) Maintained (last release Jan 2025); MongoDB binary stuck at v4.4.4 Active (follows Testcontainers .NET releases) Production

Setup & Operations

InMemory Emulator Mongo2Go Testcontainers.MongoDB Real MongoDB
Pricing ✅ Free ✅ Free ✅ Free ❌ Pay (Atlas) or self-host
In-process (no external deps) ❌ External mongod process ❌ Docker container ❌ Requires network
Fast startup ✅ Instant (~0 ms) ❌ 2–5 s ❌ 5–15 s ❌ Already running / provisioning
Docker required ✅ No ✅ No ❌ Yes ✅ No (self-host)
Works offline ✅ (after first download) ⚠️ Needs image cached ❌ Atlas requires internet
CI-friendly ✅ All environments (no deps) ⚠️ Binary compat issues on newer Ubuntu (libssl1.1) ⚠️ Docker-capable runners only ⚠️ Needs credentials / network
Multiple instances / parallel ✅ One per test class (zero cost) ⚠️ One mongod per instance (port exhaustion risk) ⚠️ One container per instance (slow, resource-heavy) ⚠️ Shared state; needs cleanup
Test isolation ✅ New instance per test ⚠️ Shared process; manual DB drop ⚠️ Shared container; manual DB drop ❌ Shared; risk of data leakage
Stable under load ✅ No sockets/network ⚠️ Occasional mongod crashes on CI ⚠️ Docker resource contention ✅ (at cost)
Platform support ✅ Any (.NET 8.0+) ⚠️ Bundled v4.4.4 needs libssl1.1 on newer Linux ✅ Any Docker host ✅ Any
No special cleanup ✅ GC disposes ⚠️ Must Dispose (kills mongod, deletes data dir) ⚠️ Must Dispose ⚠️ Manual cleanup
Community sentiment ✅ New; fast-growing ⚠️ Established but aging (MongoDB 4.4.4 only) ✅ Popular ✅ Standard
.NET target .NET 8.0+ .NET Framework 4.7.2 / .NET Standard 2.1 .NET Standard 2.0+ N/A
License MIT MIT MIT SSPL (server)
Stars 408

Detailed Feature Parity

Legend:

  • ✅ = Full support
  • ⚠️ = Partial support (details in Notes)
  • ❌ = Not supported
  • N/A = Not applicable

CRUD Operations

InMemory Mongo2Go Testcontainers Real MongoDB Notes
InsertOne / InsertMany
Find (filter, sort, skip, limit, projection)
UpdateOne / UpdateMany
ReplaceOne
DeleteOne / DeleteMany
FindOneAndDelete
FindOneAndReplace
FindOneAndUpdate
BulkWrite (ordered/unordered)
CountDocuments / EstimatedDocumentCount
Distinct InMemory: array unwinding supported
Aggregate InMemory: 34 stages
AsQueryable (LINQ) InMemory: LINQ3
Upsert (insert on no match)
ArrayFilters (positional updates)
Pipeline-style updates
Auto _id generation InMemory: writes back to POCO
MapReduce InMemory: throws NotSupportedException (deprecated in MongoDB 5.0+)

Filter Operators — Comparison

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$eq
$ne
$gt
$gte
$lt
$lte
$in InMemory: supports BsonRegularExpression values
$nin

Filter Operators — Logical

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$and
$or
$nor
$not

Filter Operators — Element & Type

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$exists
$type InMemory: all BSON type aliases (timestamp, javascript, minKey, maxKey, etc.)

Filter Operators — Array

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$all InMemory: nested $elemMatch + scalar matching
$elemMatch
$size

Filter Operators — Evaluation

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$regex (with $options)
$mod InMemory: exact comparison, truncation per spec
$expr
$text InMemory: case-insensitive word matching
$jsonSchema InMemory: allOf/anyOf/oneOf/not
$where (JavaScript) InMemory: requires JsTriggers package

Filter Operators — Bitwise

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$bitsAllSet
$bitsAllClear
$bitsAnySet
$bitsAnyClear

Filter Operators — Geospatial

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$geoWithin ($geometry, $centerSphere) InMemory: real calculations via NetTopologySuite
$geoIntersects
$near ($maxDistance, $minDistance)
$nearSphere

Update Operators — Field

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$set
$unset
$inc
$mul
$min
$max
$rename
$currentDate
$setOnInsert

Update Operators — Array

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$push (with $each, $position, $sort, $slice) InMemory: negative $position for end-relative
$pull (with subdocument matching)
$pullAll
$addToSet (with $each)
$pop
$bit (AND, OR, XOR)
$ (first matching positional)
$[] (all elements)
$[<identifier>] (filtered positional) InMemory: with arrayFilters

Projection Operators

InMemory Mongo2Go Testcontainers Real MongoDB Notes
Inclusion / exclusion
_id exclusion
Dot-notation nested fields
$slice (array)
$elemMatch
$meta (textScore) InMemory: gracefully skipped in sort

Aggregation Pipeline Stages

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$match
$project
$addFields / $set
$unset
$group InMemory: 19+ accumulators
$sort
$limit
$skip
$unwind preserveNullAndEmptyArrays supported
$lookup
$replaceRoot / $replaceWith
$count
$sortByCount
$sample
$facet
$bucket
$bucketAuto InMemory: custom output accumulators
$unionWith
$graphLookup InMemory: recursive with deduplication
$redact
$merge
$out
$setWindowFields InMemory: 22 window functions
$densify
$fill
$documents
$collStats InMemory: synthetic values
$indexStats InMemory: synthetic values
$geoNear InMemory: real geometric calculations
$search ⚠️ ✅ (Atlas) InMemory: basic substring (not Atlas Search)
$searchMeta ⚠️ ✅ (Atlas) InMemory: stub
$vectorSearch ✅ (Atlas) InMemory: brute-force exact computation
$changeStream InMemory: use Watch() API instead

Group Accumulators

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$sum / $avg / $min / $max
$first / $last
$push / $addToSet
$count
$mergeObjects
$stdDevPop / $stdDevSamp
$top / $bottom / $topN / $bottomN
$firstN / $lastN / $maxN / $minN
$median / $percentile
$accumulator (JavaScript) InMemory: requires JsTriggers package

Window Functions ($setWindowFields)

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$sum / $avg / $min / $max / $count
$push / $addToSet / $first / $last
$stdDevPop / $stdDevSamp
$rank / $denseRank / $documentNumber
$shift
$expMovingAvg
$derivative / $integral
$covariancePop / $covarianceSamp
$linearFill / $locf

Aggregation Expression Operators — Arithmetic (16)

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$add / $subtract / $multiply / $divide
$mod / $abs / $ceil / $floor
$round / $trunc InMemory: IEEE 754 round-to-even
$pow / $sqrt / $log / $log10 / $ln / $exp

Aggregation Expression Operators — Trigonometric (9)

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$sin / $cos / $tan
$asin / $acos / $atan / $atan2
$degreesToRadians / $radiansToDegrees

Aggregation Expression Operators — String (20)

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$concat / $toLower / $toUpper
$trim / $ltrim / $rtrim
$substr / $substrBytes / $substrCP
$strLenBytes / $strLenCP
$indexOfBytes / $indexOfCP
$split / $strcasecmp
$replaceOne / $replaceAll
$regexMatch / $regexFind / $regexFindAll

Aggregation Expression Operators — Comparison & Logical (13)

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$cmp / $eq / $ne / $gt / $gte / $lt / $lte
$cond / $ifNull / $switch
$and / $or / $not

Aggregation Expression Operators — Array (18)

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$arrayElemAt / $size / $isArray
$concatArrays / $in / $filter / $map
$reduce / $reverseArray / $range / $slice
$first / $last / $sortArray
$objectToArray / $arrayToObject
$zip / $indexOfArray

Aggregation Expression Operators — Set (7)

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$setUnion / $setIntersection / $setDifference
$setEquals / $setIsSubset
$anyElementTrue / $allElementsTrue

Aggregation Expression Operators — Type & Conversion (11)

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$type / $convert / $isNumber
$toBool / $toInt / $toLong / $toDouble / $toDecimal
$toString / $toDate / $toObjectId

Aggregation Expression Operators — Date (21)

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$year / $month / $dayOfMonth / $hour / $minute / $second / $millisecond
$dayOfWeek / $dayOfYear / $week / $isoWeek / $isoWeekYear / $isoDayOfWeek
$dateToString / $dateFromString InMemory: format + timezone support
$dateAdd / $dateSubtract / $dateDiff InMemory: quarter unit supported
$dateTrunc / $dateFromParts / $dateToParts

Aggregation Expression Operators — Object (4)

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$mergeObjects
$getField / $setField / $unsetField

Aggregation Expression Operators — Bitwise (4)

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$bitAnd / $bitOr / $bitXor / $bitNot

Aggregation Expression Operators — Special (8)

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$literal / $let
$binarySize / $bsonSize
$rand / $sampleRate
$toHashedIndexKey
$function (JavaScript) InMemory: requires JsTriggers package

Aggregation Expression Operators — Timestamp (2)

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$tsIncrement / $tsSecond

Indexes

InMemory Mongo2Go Testcontainers Real MongoDB Notes
Unique indexes ✅ Enforced
Compound indexes (multi-field uniqueness) ✅ Enforced
Sparse indexes ✅ Enforced
Partial filter indexes ✅ Enforced
TTL indexes ✅ Enforced (lazy eviction) InMemory: expired docs removed on query, not by background thread
Text indexes ✅ Accepted
2dsphere indexes ✅ Accepted
Hashed indexes ✅ Accepted InMemory: no sharding simulation
Wildcard indexes ✅ Accepted
CreateOne / CreateMany / List / DropOne / DropAll
Duplicate key error (proper error codes)
Index used for query optimization InMemory: always full scan; indexes stored but not used for optimization

Database & Collection Operations

InMemory Mongo2Go Testcontainers Real MongoDB Notes
GetCollection()
CreateCollection (capped, timeseries, validator, viewOn)
DropCollection
ListCollections / ListCollectionNames
RenameCollection (with DropTarget)
CreateView (pipeline-backed)
Database-level Aggregate
GetDatabase / ListDatabases / DropDatabase
RunCommand ⚠️ InMemory: supports ping, buildInfo, serverStatus, hostInfo, connectionStatus, listCommands, collStats, dbStats, count, distinct, create, drop, createIndexes, dropIndexes, aggregate, explain. Not supported: hello/isMaster, collMod, currentOp, validate, filemd5, renameCollection (via RunCommand), convertToCapped, reIndex, compact, user/role management, replication, sharding commands. Unknown commands throw CommandNotFound (code 59).
WithReadConcern / WithWriteConcern / WithReadPreference ✅ Stored InMemory: accepted but not enforced

Change Streams

InMemory Mongo2Go Testcontainers Real MongoDB Notes
Collection-level Watch()
Database-level Watch()
Client-level Watch()
Resume tokens
OperationType: Insert, Update, Replace, Delete
FullDocument / FullDocumentBeforeChange
Pipeline filtering on events
Events from all write operations

Transactions

InMemory Mongo2Go Testcontainers Real MongoDB Notes
StartSession / StartTransaction
CommitTransaction / AbortTransaction
Snapshot isolation
Automatic rollback on abort
Multi-document transactions ⚠️ Mongo2Go: requires singleNodeReplSet: true (adds ~5s to startup)
Distributed / sharded transactions

Schema Validation ($jsonSchema)

InMemory Mongo2Go Testcontainers Real MongoDB Notes
required / bsonType
minimum / maximum
minLength / maxLength / pattern
enum
minItems / maxItems
additionalProperties
allOf / anyOf / oneOf / not
validationAction / validationLevel

Capped Collections & Tailable Cursors

InMemory Mongo2Go Testcontainers Real MongoDB Notes
Capped collection (FIFO eviction) maxDocuments + maxSize
Tailable cursor / TailableAwait
Cannot delete from capped

GridFS

InMemory Mongo2Go Testcontainers Real MongoDB Notes
UploadFromBytes / UploadFromStream
DownloadAsBytes / DownloadToStream
Find / Delete / Rename

Geospatial

InMemory Mongo2Go Testcontainers Real MongoDB Notes
$geoWithin / $geoIntersects / $near / $nearSphere InMemory: NetTopologySuite for real geometric calculations
$geoNear aggregation stage
2dsphere index

Advanced Features

InMemory Mongo2Go Testcontainers Real MongoDB Notes
Fault injection InMemory exclusive: per-operation error simulation
Operation logging InMemory exclusive: query/operation recording for assertions
State export/import (JSON) ⚠️ Mongo2Go: mongoexport/mongoimport only
DI integration (UseInMemoryMongoDB) InMemory exclusive: one-line service replacement
Vector search ($vectorSearch) ✅ (Atlas) InMemory: brute-force computation
$search / $searchMeta (text) ⚠️ ✅ (Atlas) InMemory: basic substring (not Atlas Search)
JavaScript expressions ($function, $accumulator, $where) InMemory: via optional JsTriggers package (Jint)
SDK version drift detection InMemory exclusive: alerts when driver adds new members
InMemoryMongo.Create() factory InMemory exclusive: instant standalone collection
Collation (culture-aware) InMemory: .NET CultureInfo (may differ from ICU on edge cases)
Views (pipeline-backed)
Time series collections ⚠️ InMemory: stub (accepted in CreateCollection)
Authentication / authorization InMemory: not simulated
Replica set topology ⚠️ Mongo2Go: single-node replica set only
Sharding
Client-Side Field Level Encryption (CSFLE) Requires native cryptd libraries
Queryable Encryption Requires server-side support
Command monitoring / APM events InMemory: ClusterConfigurator events not fired
Query plan optimization (indexes used for queries) InMemory: always full scan
Aggregation 100 MB memory limit InMemory: unconstrained
Cursor idle timeout InMemory: cursors never expire
Data persistence across restarts ⚠️ InMemory: via ExportState/ImportState; Testcontainers: volume mount
Multiple databases
mongoimport / mongoexport Mongo2Go: built-in convenience wrappers

Summary Scorecard

Counts based on the detailed tables above. "Applicable" excludes cloud-only Atlas features ($search, $vectorSearch) that no local testing tool supports identically.

Category InMemory Mongo2Go Testcontainers Real MongoDB
CRUD operations (18) ✅ 17/18 ✅ 18/18 ✅ 18/18 ✅ 18/18
Filter operators (27) ✅ 27/27 ✅ 27/27 ✅ 27/27 ✅ 27/27
Update operators (18) ✅ 18/18 ✅ 18/18 ✅ 18/18 ✅ 18/18
Projection operators (6) ✅ 6/6 ✅ 6/6 ✅ 6/6 ✅ 6/6
Aggregation stages (34) ✅ 32/34 ✅ 32/34 ✅ 32/34 ✅ 34/34
Expression operators (113+) ✅ 113/113 ✅ 113/113 ✅ 113/113 ✅ 113/113
Group accumulators (19+) ✅ 19/19 ✅ 19/19 ✅ 19/19 ✅ 19/19
Window functions (22) ✅ 22/22 ✅ 22/22 ✅ 22/22 ✅ 22/22
Index types (9) ⚠️ 9/9 stored, 5/9 enforced ✅ 9/9 ✅ 9/9 ✅ 9/9
Change stream features (8) ✅ 8/8 ✅ 8/8 ✅ 8/8 ✅ 8/8
Transaction features (6) ⚠️ 4/6 ⚠️ 5/6 ✅ 6/6 ✅ 6/6
InMemory-exclusive features (6) ✅ 6/6 ❌ 0/6 ❌ 0/6 ❌ 0/6

InMemory Emulator Strengths

  • 113+ aggregation expression operators — full pipeline support with 34 stages
  • Instant startup — no Docker, no binary download, no network
  • Perfect test isolation — new instance per test, no shared state, no cleanup
  • Fault injection — simulate errors per-operation for retry/resilience testing
  • Operation logging — record all operations for test assertions
  • State export/import — JSON-based snapshot and restore for test setup
  • DI integration — one-line setup via UseInMemoryMongoDB()
  • No platform restrictions — any OS that runs .NET 8.0+
  • No port conflicts — multiple instances run in parallel without coordination
  • SDK drift detection — alerts when new driver interface members appear

InMemory Emulator Limitations (things Mongo2Go / Testcontainers / Real MongoDB do that InMemory doesn't)

  • MapReduce — deprecated in MongoDB 5.0+; throws NotSupportedException
  • Query plan optimization — indexes stored but never used for query routing; always full scan
  • Aggregation 100 MB memory limit — unconstrained (no allowDiskUse enforcement)
  • Authentication / authorization — ReadConcern/WriteConcern/ReadPreference stored but not enforced
  • Replica set topology — single in-memory instance (no failover/election simulation)
  • Sharding — no shard key routing or chunk migration
  • Client-Side Field Level Encryption (CSFLE) — requires native mongocryptd libraries
  • Command monitoring / APM eventsClusterConfigurator event subscribers not fired
  • Cursor idle timeout — in-memory cursors never expire
  • Atlas Search ($search full fidelity) — basic substring only, not NLP/BM25
  • ⚠️ TTL eviction — lazy (on query) rather than background thread
  • ⚠️ Collation — uses .NET CultureInfo; may differ from ICU on edge cases

When to Use Each

InMemory Emulator

  • Unit tests and integration tests in CI
  • Local development without Docker or binary dependencies
  • Testing retry logic via fault injection
  • Fast feedback loops (instant startup, zero teardown)
  • Deterministic, reproducible test runs
  • No external dependencies
  • When you need full aggregation pipeline testing (34 stages, 113+ operators)
  • Parallel test execution without coordination

Mongo2Go

  • When you need 100% MongoDB wire-protocol fidelity
  • When testing features not reimplemented (MapReduce, command monitoring)
  • Legacy projects on .NET Framework 4.7.2 / .NET Standard 2.1
  • When Docker isn't available but you need "real" MongoDB behavior

Testcontainers.MongoDB

  • Full-fidelity end-to-end testing with Docker available
  • Testing specific MongoDB server versions (choose image tag)
  • Testing sharding, encryption, or distributed transactions
  • When you need APM/command monitoring event verification
  • When Docker is already part of your CI infrastructure

Real MongoDB

  • Final acceptance testing against production-like environment
  • Performance benchmarking with real indexes and query plans
  • Verifying authentication, RBAC, and encryption
  • Testing with production data volumes
  • Atlas-specific features ($search with BM25, $vectorSearch with ANN)

See Also

Clone this wiki locally