Skip to content

State Persistence

Aryeh Citron edited this page May 12, 2026 · 2 revisions

State Persistence

Manual Export/Import

Export State

var db = result.Database as InMemoryMongoDatabase;
string json = db!.ExportState();
// json contains: {"collections":{"orders":[{...}, {...}], "customers":[{...}]}}

Import State

var db = result.Database as InMemoryMongoDatabase;
db!.ImportState(json);
// Replaces all documents in all collections

File Operations

// Save snapshot to disk
db.ExportStateToFile("test-snapshot.json");

// Restore from disk
db.ImportStateFromFile("test-snapshot.json");

Note: Import is a full replacement — existing documents are cleared before importing.

Note: Change streams and change logs are not persisted across Export/Import cycles.

See Also

Clone this wiki locally