# From self-managed MongoDB to Azure DocumentDB

### Step 1: Download dsync

[![Adiom on Azure Marketplace](https://assetsprod.microsoft.com/mpn/en-us/ms-azure-marketplace.png)](https://azuremarketplace.microsoft.com/en-us/marketplace/apps/adiom.adiom_dsync_vm)

{% hint style="info" %}
Working on a large-scale production environment? Use our horizontally scalable [Enterprise offering.](https://docs.adiom.io/enterprise/scalable-deployment)
{% endhint %}

Use Docker (`markadiom/dsync`) or download the latest release from the [GitHub Releases](https://github.com/adiom-data/dsync/releases/latest) page. Note that on Mac devices you may need to configure a security exception to execute the binary by following [these steps](https://support.apple.com/en-ca/guide/mac-help/mh40616/mac).

Alternatively, you can build dsync from the source code.

```bash
git clone https://github.com/adiom-data/dsync.git
cd dsync
go build
```

{% hint style="info" %}
You can use Homebrew to easily install Dsync on your Mac:

```
brew install adiom-data/homebrew-tap/dsync
```

{% endhint %}

***

### Step 2: Prepare the source MongoDB instance

{% hint style="warning" %}
If you already have the desired source MongoDB instance up and running, you can skip this step.
{% endhint %}

1. Install [MongoDB](https://www.mongodb.com/docs/manual/administration/install-community/)
2. Start a local MongoDB instance
3. Load sample data

```bash
# Start a new mongod instance on localhost:27017 with dbpath ~/temp/data_d

mkdir ~/temp
cd ~/temp
mkdir data_d
mongod --dbpath data_d --logpath mongod_d.log --fork --port 27017

# Load sample data
git clone https://github.com/mcampo2/mongodb-sample-databases
cd mongodb-sample-databases
mongorestore dump/sample_mflix
```

***

### Step 3: Prepare the destination DocumentDB instance

{% hint style="warning" %}
If you already have the desired source Cosmos DB instance up and running, you can skip this step.
{% endhint %}

Follow official Azure documentation to set up a DocumentDB instance. For example, these are the instructions for setting up Azure DocumentDB (formerly Cosmos DB vCore for MongoDB) instance using Azure Portal: <https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/vcore/quickstart-portal>

Make sure to note the DocumentDB cluster MongoDB connection string: <https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/vcore/quickstart-portal#get-cluster-credentials>

***

### Step 3: Start dsync

```bash
# Use the read-write connection string from the Azure Portal
export COSMOS_DEST=

# Feel free to use your own MongoDB connection string
export MDB_SRC='mongodb://localhost:27017' 

# Set the mode to InitialSync if the source MongoDB is NOT a replica set
# Otherwise skip the option altogether or set it to Full to switch to CDC after Initial Sync
./dsync --mode InitialSync --progress --logfile dsync.log $MDB_SRC $COSMOS_DEST 
```

Now Dsync should be running! Feel free to interrupt the sync process (via Ctrl+C) it once the initial sync is done. The sample database has a few million records - allow 5-10 minutes for the process to complete.

***

### Step 4: Check the data

```bash
mongosh $COSMOS_DEST
```

Congratulations! You should be able to access the 'sample\_mflix' database and see the collections in it that were migrated from the local MongoDB instance.

***

### Contact us

Please reach out to us [by email](mailto:info@adiom.io) and on [Discord](https://discord.gg/r4xzVfMQeU) for commercial inquiries and support.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.adiom.io/getting-started/quickstart/from-mongodb-to-cosmos-db.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
