Cosmos DB NoSQL to MongoDB
Steps for executing a live production migration from Cosmos DB NoSQL to MongoDB using Dsynct.
Prerequisites
Set up Temporal and SigNoz (or another OTEL collector). You can follow the instructions in Running Dsynct
Obtain Cosmos DB credentials - URI and Primary Key ("Settings" -> "Keys" in the Azure Portal)
Obtain MongoDB connection string - for the destination cluster
Enable "All Versions and Deletes" for your Cosmos DB container ("Settings" -> "Features" in the Azure Portal)
If you can't turn on the feature, you can run the Cosmos DB NoSQL connector with the
COSMOS_DISABLE_ALL_VERSIONS_AND_DELETES=trueenvironment variable. In that case Dsync will not be able to replicate delete events from Cosmos DB.
Data type and ID considerations
Cosmos DB NoSQL uses JSON while MongoDB uses BSON, so a data transformation is required.
The Cosmos DB NoSQL ID format is composed of the shard key followed by the id field. MongoDB uses a single _id field. A transform config must map between these ID formats.
See IDs, Data Types and CDC Events for full details on JSON to BSON mappings.
Simple case: shard key is /id
When the shard key is /id, the Cosmos DB ID contains only the id field. The transform maps id to _id:
# transform.yaml
defaultmapping: default
mappings:
- namespace: default
delete: ["id"]
add: ["_id"]
mapid: id
cel:
_id: idWith a shard key prefix
When the shard key is a separate field (e.g. /region), the Cosmos DB ID is multi-part (e.g. ["us-east", "123"]). You need to use idkeys to declare the source ID fields and collapse them into a single _id:
Worker VM setup
Use docker logs -f cosmosnosqlconnector or docker logs -f dsyncworker to follow container logs.
Running the workflow
Last updated