title | description | keywords | services | author | ms.service | ms.component | ms.topic | ms.date | ms.author |
---|---|---|---|---|---|---|---|---|---|
MongoDB connection string for an Azure Cosmos DB account |
Learn how to connect your MongoDB app to an Azure Cosmos DB account by using a MongoDB connection string. |
mongodb connection string |
cosmos-db |
slyons |
cosmos-db |
cosmosdb-mongo |
conceptual |
12/19/2017 |
sclyon |
Learn how to connect your MongoDB app to an Azure Cosmos DB account by using a MongoDB connection string. You can then use an Azure Cosmos DB database as the data store for your MongoDB app.
This tutorial provides two ways to retrieve connection string information:
- The quick start method, for use with .NET, Node.js, MongoDB Shell, Java, and Python drivers
- The custom connection string method, for use with other drivers
- An Azure account. If you don't have an Azure account, create a free Azure account now.
- An Azure Cosmos DB account. For instructions, see Build a MongoDB API web app with .NET and the Azure portal.
-
In an Internet browser, sign in to the Azure portal.
-
In the Azure Cosmos DB blade, select the API for MongoDB account.
-
In the left pane of the account blade, click Quick start.
-
Choose your platform (.NET, Node.js, MongoDB Shell, Java, Python). If you don't see your driver or tool listed, don't worry--we continuously document more connection code snippets. Please comment below on what you'd like to see. To learn how to craft your own connection, read Get the account's connection string information.
-
Copy and paste the code snippet into your MongoDB app.
-
In an Internet browser, sign in to the Azure portal.
-
In the Azure Cosmos DB blade, select the API for MongoDB account.
-
In the left pane of the account blade, click Connection String.
-
The Connection String blade opens. It has all the information necessary to connect to the account by using a driver for MongoDB, including a preconstructed connection string.
Important
Azure Cosmos DB has strict security requirements and standards. Azure Cosmos DB accounts require authentication and secure communication via SSL.
Azure Cosmos DB supports the standard MongoDB connection string URI format, with a couple of specific requirements: Azure Cosmos DB accounts require authentication and secure communication via SSL. So, the connection string format is:
mongodb://username:password@host:port/[database]?ssl=true
The values of this string are available in the Connection String blade shown earlier:
- Username (required): Azure Cosmos DB account name.
- Password (required): Azure Cosmos DB account password.
- Host (required): FQDN of the Azure Cosmos DB account.
- Port (required): 10255.
- Database (optional): The database that the connection uses. If no database is provided, the default database is "test."
- ssl=true (required)
For example, consider the account shown in the Connection String blade. A valid connection string is:
mongodb://contoso123:0Fc3IolnL12312asdfawejunASDF@asdfYXX2t8a97kghVcUzcDv98hawelufhawefafnoQRGwNj2nMPL1Y9qsIr9Srdw==@contoso123.documents.azure.com:10255/mydatabase?ssl=true
- Learn how to use Studio 3T (MongoChef) with an Azure Cosmos DB API for MongoDB account.
- Explore the Azure Cosmos DB API for MongoDB by viewing samples.