-
Notifications
You must be signed in to change notification settings - Fork 0
API Reference
Aryeh Citron edited this page May 12, 2026
·
2 revisions
Static factory for creating in-memory MongoDB instances.
| Method | Returns | Description |
|---|---|---|
Create<T>(collectionName) |
InMemoryMongoResult<T> |
Creates a single-collection setup |
Builder() |
InMemoryMongoBuilder |
Creates a multi-database builder |
| Property | Type | Description |
|---|---|---|
Client |
IMongoClient |
The in-memory client |
Database |
IMongoDatabase |
The in-memory database |
Collection |
IMongoCollection<T> |
The in-memory collection |
| Method | Returns | Description |
|---|---|---|
AddDatabase(name, configure) |
InMemoryMongoBuilder |
Add a database with collections |
Build() |
IMongoClient |
Build the multi-database setup |
| Method | Returns | Description |
|---|---|---|
AddCollection<T>(name) |
DatabaseBuilder |
Add a typed collection |
| Method | Description |
|---|---|
GetDatabase(name) |
Get or create an in-memory database |
ListDatabases() |
List all databases |
ListDatabaseNames() |
List all database names |
DropDatabase(name) |
Drop a database |
StartSession() |
Start a client session (transactions) |
Watch() |
Open a client-level change stream |
WithReadConcern() / WithWriteConcern() / WithReadPreference()
|
Return configured client (settings stored, not enforced) |
Dispose() |
No-op. IMongoClient extends IDisposable in Driver 3.x |
| Method | Description |
|---|---|
GetCollection<T>(name) |
Get or create a collection |
CreateCollection(name, options) |
Create a collection (capped, validation, time series) |
DropCollection(name) |
Drop a collection |
ListCollections() |
List all collections |
ListCollectionNames() |
List collection names |
RenameCollection(old, new) |
Rename a collection |
RunCommand<T>(command) |
Execute a database command |
Aggregate<T>(pipeline) |
Database-level aggregation |
CreateView(viewName, source, pipeline) |
Create a view |
Watch() |
Open a database-level change stream |
ExportState() / ImportState(json)
|
Export/import all collection data as JSON |
ExportStateToFile(path) / ImportStateFromFile(path)
|
File-based export/import |
ClearDocuments() |
Clear all documents from all collections |
| Method | Description |
|---|---|
InsertOne / InsertOneAsync
|
Insert a single document |
InsertMany / InsertManyAsync
|
Insert multiple documents |
Find / FindSync / FindAsync
|
Query documents |
UpdateOne / UpdateOneAsync
|
Update first matching document |
UpdateMany / UpdateManyAsync
|
Update all matching documents |
ReplaceOne / ReplaceOneAsync
|
Replace first matching document |
DeleteOne / DeleteOneAsync
|
Delete first matching document |
DeleteMany / DeleteManyAsync
|
Delete all matching documents |
FindOneAndDelete / FindOneAndReplace / FindOneAndUpdate
|
Atomic find-and-modify |
BulkWrite / BulkWriteAsync
|
Execute multiple write operations |
CountDocuments / EstimatedDocumentCount
|
Count documents |
Distinct / DistinctMany
|
Get distinct field values |
| Method | Description |
|---|---|
Aggregate / AggregateAsync
|
Execute aggregation pipeline |
AggregateToCollection |
Execute pipeline, write results to collection |
| Method | Description |
|---|---|
Watch / WatchAsync
|
Open a change stream on this collection |
| Property | Description |
|---|---|
Indexes |
IMongoIndexManager<T> - create, drop, list indexes |
| Property | Type | Description |
|---|---|---|
FaultInjector |
Action<string, BsonDocument?>? |
Hook to simulate failures |
OperationLog |
OperationLog |
Records all operations for test assertions |
| Method | Description |
|---|---|
UploadFromBytes / UploadFromBytesAsync
|
Upload file from byte array |
UploadFromStream / UploadFromStreamAsync
|
Upload file from stream |
DownloadAsBytes / DownloadAsBytesAsync
|
Download file as byte array |
DownloadToStream / DownloadToStreamAsync
|
Download file to stream |
DownloadAsBytesByName / DownloadToStreamByName
|
Download by filename |
Delete / DeleteAsync
|
Delete a file |
Rename / RenameAsync
|
Rename a file |
Find / FindAsync
|
Find files by filter |
Drop / DropAsync
|
Drop the entire bucket |
| Method | Description |
|---|---|
GetAll() |
Get all recorded operations |
GetByType(type) |
Get operations by type (e.g., "InsertOne") |
Clear() |
Clear all recorded operations |
Count |
Number of recorded operations |
| Property | Type | Description |
|---|---|---|
Type |
string |
Operation type (e.g., "InsertOne", "UpdateOne") |
Filter |
BsonDocument? |
The filter used |
Update |
BsonDocument? |
The update document |
Document |
BsonDocument? |
The document involved |
Pipeline |
BsonDocument[]? |
The pipeline stages |
Timestamp |
DateTimeOffset |
When the operation occurred |
| Method | Description |
|---|---|
UseInMemoryMongoDB(options) |
Replace IMongoClient + IMongoDatabase + IMongoCollection |
UseInMemoryMongoCollections(options) |
Replace only IMongoCollection registrations |
- Features — Feature reference
- Setup Guide — DI patterns
Getting Started
Integration & Dependency Injection
Data Management
Reference
- Feature Comparison
- Features
- Filter & Update Operators
- Aggregation Pipeline
- LINQ Support
- API Reference
Help