Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
APPLIES TO:
MongoDB
Learn how to connect your MongoDB app to an Azure Cosmos DB 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 quickstart method, for use with .NET, Node.js, MongoDB Shell, Java, and Python drivers.
- The custom connection string method, for use with other drivers.
Prerequisites
There are two items required
An Azure account.
An Azure Cosmos DB account. For instructions, see Quickstart: Azure Cosmos DB for MongoDB driver for Node.js.
Get the MongoDB connection string by using the quick start
Follow the below steps:
In an Internet browser, sign in to the Azure portal.
In the Azure Cosmos DB pane, select the API.
In the left pane of the account pane, select 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. Comment 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.
Get the MongoDB connection string to customize
Follow the below steps:
In an Internet browser, sign in to the Azure portal.
In the Azure Cosmos DB pane, select the API.
In the left pane of the account pane, select Connection strings.
The Connection strings pane opens. It has all the information necessary to connect to the account by using a driver for MongoDB, including a preconstructed connection string.
Connection string requirements
Important
Azure Cosmos DB has strict security requirements and standards. Azure Cosmos DB accounts require authentication and secure communication via TLS.
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 TLS. The connection string format is:
mongodb://username:password@host:port/[database]?ssl=true
The values of this string are:
- 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 strings pane. A valid connection string is:
mongodb://contoso123:0Fc3IolnL12312asdfawejunASDF@asdfYXX2t8a97kghVcUzcDv98hawelufhawefafnoQRGwNj2nMPL1Y9qsIr9Srdw==@contoso123.documents.azure.com:10255/mydatabase?ssl=true
Driver requirements
All drivers that support wire protocol version 3.4 or greater support Azure Cosmos DB for MongoDB.
- Client drivers must support the Service Name Identification (SNI) TLS extension and/or the appName connection string option.
- If the
appName
parameter is provided, it must be included as found in the connection string value in the Azure portal.