Migrate MongoDB  To CosmosDB

Pre-requisites-

  • A MongoDB dump stored in Azure Blob Storage (e.g., from mongodump).
  • A Cosmos DB for MongoDB vCore cluster with connection string and credentials.
  • Azure Cloud Shell access.
  • Install mongorestore in Cloud Shell (MongoDB tools).

Steps to perform backup and restore-

Step-1: Connect to the source MongoDB server and take a data dump using the mongodump utility.

Step-2: Install AzCopy on Linux by using a package manager.

Download the repository configuration package.

https://packages.microsoft.com/config/<distribution>/<version>/packages-microsoft-prod.rpm

Install the repository configuration package.

Delete the repository configuration package after you’ve installed it.

Update the package index files.

Install AzCopy.

Step-3:Copy the MongoDB dump file from the source server to a Microsoft Azure Blob Storage container using the AzCopy tool.

Generate SAS token:

Step-4: Connect to the Microsoft Azure portal, navigate to the Blob Storage account, open the target container, and locate the uploaded backup (bkpp) folder.

Step-5: Download the backup file from Azure Blob Storage to your local environment or Azure Cloud Shell using the AzCopy tool

Step-6: Install MongoDB Tools in Azure Cloud Shell

Step-7: Connect to Azure Cosmos DB and run the command to list all available databases to verify the connection and check existing databases.

Step-8: Restore the MongoDB backup to Azure Cosmos DB for MongoDB vCore directly from Azure Blob Storage using Azure Cloud Shell by downloading the backup with azcopy and restoring it using mongorestore.

Step-9: Verify that the database and its collections have been successfully restored by connecting to Azure Cosmos DB and listing the databases and collections.

  • To check if any views were restored, connect to the database and run a query to list all collections and filter those of type view
  • Check that indexes have been successfully restored by listing all indexes for each collection in the database

Note: Indexes are migrated when you use:

  1. System Databases Not Migrated – Cannot migrate admin, local, or config databases.
  2. Users and Roles Not Transferred – MongoDB users, roles, and authentication settings are not migrated.
  3. Unsupported MongoDB Commands – Commands like isMaster, repairDatabase, etc., are not supported.
  4. No Server-side JavaScript or MapReduce – Features like db.eval() and mapReduce are not available.
  5. Partial BSON Type Support – Certain BSON types (e.g., DBRef) may not be fully supported.
  6. No Internal Auth User Migration – MongoDB internal authentication users cannot be migrated.
  7. Limited Aggregation Support – Aggregation stages like $lookup, $out, and $merge are not supported.
  8. Automatic Indexing -All fields are indexed by default, custom index control is limited.
  9. Limited Compound Indexes – Restrictions apply to compound indexes in certain scenarios.
  10. No Change Streams Support – Real-time change tracking via change streams is not available.
  11. TTL Index Limitations – Time-to-Live support is basic and limited.
  12. No Sharding After Deployment – Sharding is not supported once the cluster is created.
  13. Index Size Restriction – Index keys must be ≤ 2048 bytes.
  14. Max Document Size – Maximum document size is 2 MB.
  15. Supported MongoDB Versions – Only MongoDB 4.2 and 5.0 are supported. MongoDB 6.0+ is not yet supported.
  16. No Replica Set Customization – You cannot access or modify replicas set configurations.
  17. No Access to Server Logs or Configs – Direct access to MongoDB logs or config files is not provided.
  18. Limited Backup/Restore Features – Native backups are supported, but no point-in-time restore is available yet.
  19. Monitoring via Azure Monitor Only – Standard MongoDB logging tools like mongod.log are not accessible.
  20. No Instance-level Tuning – Cannot modify engine-level settings like WiredTiger options.

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories


Recent Post