title | description | keywords | services | author | manager | editor | documentationcenter | ms.assetid | ms.service | ms.workload | ms.tgt_pltfrm | ms.devlang | ms.topic | ms.date | ms.author |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
MongoDB connection string for DocumentDB account | Microsoft Docs |
Learn how to connect your MongoDB app to an Azure DocumentDB account using a MongoDB connection string. |
mongodb connection string |
documentdb |
AndrewHoh |
jhubbard |
e36f7375-9329-403b-afd1-4ab49894f75e |
documentdb |
data-services |
na |
na |
article |
01/09/2016 |
anhoh |
Learn how to connect your MongoDB app to an Azure DocumentDB account using a MongoDB connection string. By connecting your MongoDB app to an Azure DocumentDB database, you can use a DocumentDB 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.
- A DocumentDB account. For instructions, see Create a DocumentDB account for use with MongoDB apps.
-
In an internet browser, sign in to the Azure Portal.
-
In the NoSQL (DocumentDB) blade, select the DocumentDB account with protocol support for MongoDB.
-
In the Left Navigation bar of the account blade, click Quick start.
-
Choose your platform (.NET driver, Node.js driver, MongoDB Shell, Java driver, Python driver). 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 and read Get the account's connection string information to learn how to craft your own connection.
-
Copy and paste the code snippet into your MongoDB app, and you are ready to go.
-
In an internet browser, sign in to the Azure Portal.
-
In the NoSQL (DocumentDB) blade, select the DocumentDB account with protocol support for MongoDB.
-
In the Left Navigation bar of the account blade, click Connection String.
-
The Connection String Information blade opens and has all the information necessary to connect to the account using a driver for MongoDB, including a pre-constructed connection string.
Important
DocumentDB has strict security requirements and standards. DocumentDB accounts require authentication and secure communication via SSL.
It is important to note that DocumentDB supports the standard MongoDB connection string URI format, with a couple of specific requirements: DocumentDB accounts require authentication and secure communication via SSL. Thus, the connection string format is:
mongodb://username:password@host:port/[database]?ssl=true
Where the values of this string are available in the Connection String blade shown above.
- Username (required)
- DocumentDB account name
- Password (required)
- DocumentDB account password
- Host (required)
- FQDN of DocumentDB account
- Port (required)
- 10250
- Database (optional)
- The default database used by the connection (if no database is provided, the default database is "test")
- ssl=true (required)
For example, consider the account shown in the Connection String Information above. A valid connection string is:
mongodb://contoso123:0Fc3IolnL12312asdfawejunASDF@asdfYXX2t8a97kghVcUzcDv98hawelufhawefafnoQRGwNj2nMPL1Y9qsIr9Srdw==@anhohmongo.documents.azure.com:10250/mydatabase?ssl=true
- Learn how to use MongoChef with a DocumentDB account with protocol support for MongoDB.
- Explore DocumentDB with protocol support for MongoDB samples.