Events
Jan 14, 8 PM - Feb 25, 7 PM
Azure Cosmos DB Conf 2025 Call for Proposals
Submit your session proposal by Feb. 25th and be part of Azure Cosmos DB Conf 2025.This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
APPLIES TO:
MongoDB vCore
In this tutorial, you use MongoDB native tools to perform an offline (one-time) migration of a database from an on-premises or cloud instance of MongoDB to Azure Cosmos DB for MongoDB vCore. The MongoDB native tools are a set of binaries that facilitate data manipulation on an existing MongoDB instance. The focus of this doc is on migrating data out of a MongoDB instance using mongoexport/mongoimport or mongodump/mongorestore. Since the native tools connect to MongoDB using connection strings, you can run the tools anywhere. The native tools can be the simplest solution for small datasets where total migration time isn't a concern.
Prior to starting the migration, make sure you have prepared your Azure Cosmos DB for MongoDB vCore account and your existing MongoDB instance for migration.
readWrite
permissions, unless one already exists. You eventually use this credential with the mongoexport and mongodump tools.Tip
We recommend running these tools within the same network as the MongoDB instance to avoid further firewall issues.
There are some high-level considerations when choosing the right MongoDB native tool for your offline migration.
Migrate a collection from the source MongoDB instance to the target Azure Cosmos DB for MongoDB vCore account using your preferred native tool. For more information on selecting a tool, see native MongoDB tools
Tip
If you simply have a small JSON file that you want to import into Azure Cosmos DB for MongoDB vCore, the mongoimport tool is a quick solution for ingesting the data.
To export the data from the source MongoDB instance, open a terminal and use any of three methods listed here.
Specify the --host
, --username
, and --password
arguments to connect to and export JSON records.
mongoexport \
--host <hostname><:port> \
--username <username> \
--password <password> \
--db <database-name> \
--collection <collection-name> \
--out <filename>.json
Export a subset of the MongoDB data by adding a --query
argument. This argument ensures that the tool only exports documents that match the filter.
mongoexport \
--host <hostname><:port> \
--username <username> \
--password <password> \
--db <database-name> \
--collection <collection-name> \
--query '{ "quantity": { "$gte": 15 } }' \
--out <filename>.json
Export data from Azure Cosmos DB for MongoDB vCore.
mongoexport \
--uri <target-connection-string>
--db <database-name> \
--collection <collection-name> \
--query '{ "quantity": { "$gte": 15 } }' \
--out <filename>.json
Import the previously exported file into the target Azure Cosmos DB for MongoDB vCore account.
mongoimport \
--file <filename>.json \
--type json \
--db <database-name> \
--collection <collection-name> \
--ssl \
--uri <target-connection-string>
Monitor the terminal output from mongoimport. The output prints lines of text to the terminal with updates on the import operation's status.
Events
Jan 14, 8 PM - Feb 25, 7 PM
Azure Cosmos DB Conf 2025 Call for Proposals
Submit your session proposal by Feb. 25th and be part of Azure Cosmos DB Conf 2025.Training
Module
Migrate to vCore-based Azure Cosmos DB for MongoDB - Training
Migrate to vCore-based Azure Cosmos DB for MongoDB.
Certification
Microsoft Certified: Azure Cosmos DB Developer Specialty - Certifications
Write efficient queries, create indexing policies, manage, and provision resources in the SQL API and SDK with Microsoft Azure Cosmos DB.