Cosmos DB NoSQL to MongoDB

Steps for executing a live production migration from Cosmos DB NoSQL to MongoDB using Dsynct.

Prerequisites

  1. Set up Temporal and SigNoz (or another OTEL collector). You can follow the instructions in Running Dsynct

  2. Obtain Cosmos DB credentials - URI and Primary Key ("Settings" -> "Keys" in the Azure Portal)

  3. Obtain MongoDB connection string - for the destination cluster

  4. Enable "All Versions and Deletes"arrow-up-right for your Cosmos DB container ("Settings" -> "Features" in the Azure Portal)

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 Transform Data Types 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: id

With 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:

circle-info

Adjust idkeys and the cel expressions to match your Cosmos DB container's shard key configuration. See the multi-part ID examples for more patterns.

Worker VM setup

circle-info

If no ID or data type transformation is needed, you can omit the --transform flag, the dsync-transform:// argument, and the -v volume mount.

Running the workflow

Last updated