Documents and MongoDB · Engineering
Migrating from MongoDB to NonoDB
A practical migration path: ObjectId handling, indexes, BSON types, cutover, rollback, and the parts that need application changes.
A MongoDB migration is not only a data copy. It is a check of every assumption the application makes about sessions, transactions, indexes, change streams, and query semantics.
NonoDB provides a wire listener for driver compatibility and an NDJSON importer for bulk migration. A safe migration usually uses both: export or stream the data, validate it, then cut over with a rollback path.
1. Inventory the application
Before moving data, list:
- every MongoDB driver and version;
- every collection and index, including sparse, partial, TTL, and text indexes;
- every use of sessions, transactions, change streams, and retryable writes;
- every query operator and aggregation stage outside the documented subset;
- every place that assumes collation, wildcard indexes, or MongoDB-specific BSON.
The MongoDB compatibility page has the current supported matrix. Anything outside it is an application change, not an import problem.
2. Decide how to preserve _id
NonoDB accepts string and ObjectId _id values. ObjectIds are stored with an internal key prefix and returned as BSON ObjectIds on the wire. Mixed string/ObjectId collections are allowed.
The HTTP importer has a caveat: common source ObjectId forms are converted to a stable string for HTTP imports. If the application needs real ObjectId _id values, use the MongoDB wire listener or Extended JSON {"$oid": "..."} and verify the result. A missing _id gets a generated UUID, so re-importing the same file can create duplicates.
3. Export to NDJSON and a manifest
The importer consumes one JSON object per line, not a JSON array:
{"_id":"u1","name":"Ada","created_at":{"$date":"2026-01-01T00:00:00Z"}}{"_id":"u2","name":"Grace","balance":{"$numberDecimal":"120.50"}}A manifest lists collections, files, TTL defaults, and indexes:
{ "version": 1, "collections": [ { "name": "users", "file": "users.jsonl", "indexes": [ {"fields": ["email"], "unique": true} ] } ]}Indexes are created after documents are loaded. That is faster for large imports, but a unique index fails if the source contains duplicates or multiple missing values. A plain unique index treats a missing field as null, so at most one document may omit it; use a sparse index when many documents may omit the field.
4. Check the limits
The importer defaults to 500 documents or 3,000,000 encoded bytes per request. Documents are limited to 1 MiB and request bodies to 4 MiB. Vault collections are not supported by the generic importer.
Unsupported BSON includes Code, CodeWithScope, Symbol, DBPointer, and Undefined. Dates, Decimal128, binary/UUID, ObjectId, timestamps, MinKey/MaxKey, and stored regex values are supported.
5. Validate before cutover
Do not stop at “import finished”. Validate:
- document counts per collection;
- checksums or sampled field-by-field comparisons;
- index definitions and uniqueness;
- date and numeric round trips;
- IDs used by foreign references;
- TTL behavior for date fields;
- the application’s critical query shapes with
explain.
The migration tooling supports a quiesced import and an opt-in MongoDB wire shadow mode that writes to both systems and produces a JSONL diff report. Shadow mode is useful for finding read/write differences before the final switch.
6. Cut over with a rollback
The safe sequence is:
- Quiesce writes or enter shadow mode.
- Take a final export and import.
- Run validation and application smoke tests.
- Switch reads, then writes.
- Keep the old MongoDB snapshot and a NonoDB backup until the rollback window closes.
If the application depends on sessions, transactions, or change streams, cutover is not a configuration change. Those flows need a design pass first: write_batch for atomic groups, outbox events or watch instead of change streams, and application-level coordination where MongoDB provided a transaction.
7. Know when not to migrate
If the application needs multi-document transactions, sharding, collation, Atlas Search, or a large MongoDB ecosystem, staying on MongoDB may be cheaper than changing the application. NonoDB is a good fit when the workload is mostly CRUD, indexes, aggregation, and local durability, and when a smaller operational footprint matters.
The migration guide contains the full importer options, source recipes, and validation commands.