|
1 | 1 | ---
|
2 | 2 | title: Connect a MongoDB application to Azure Cosmos DB
|
3 |
| -description: Learn how to connect a MongoDB app to Azure Cosmos DB by getting the connection string from Azure portal |
| 3 | +description: Learn how to connect a MongoDB app to Azure Cosmos DB by getting the connection string from Azure portal. |
4 | 4 | author: gahl-levy
|
5 | 5 | ms.author: gahllevy
|
6 | 6 | ms.service: cosmos-db
|
7 | 7 | ms.subservice: mongodb
|
8 | 8 | ms.custom: ignite-2022
|
9 | 9 | ms.topic: how-to
|
10 |
| -ms.date: 08/26/2021 |
| 10 | +ms.date: 03/14/2023 |
11 | 11 | ms.reviewer: mjbrown
|
12 | 12 | adobe-target: true
|
13 | 13 | adobe-target-activity: DocsExp-A/B-384740-MongoDB-2.8.2021
|
14 | 14 | adobe-target-experience: Experience B
|
15 | 15 | adobe-target-content: ./connect-mongodb-account-experimental
|
16 | 16 | ---
|
| 17 | + |
17 | 18 | # Connect a MongoDB application to Azure Cosmos DB
|
| 19 | + |
18 | 20 | [!INCLUDE[MongoDB](../includes/appliesto-mongodb.md)]
|
19 | 21 |
|
20 | 22 | 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.
|
21 | 23 |
|
22 | 24 | This tutorial provides two ways to retrieve connection string information:
|
23 | 25 |
|
24 |
| -- [The quickstart method](#get-the-mongodb-connection-string-by-using-the-quick-start), for use with .NET, Node.js, MongoDB Shell, Java, and Python drivers |
25 |
| -- [The custom connection string method](#get-the-mongodb-connection-string-to-customize), for use with other drivers |
| 26 | +* [The quickstart method](#get-the-mongodb-connection-string-by-using-the-quick-start), for use with .NET, Node.js, MongoDB Shell, Java, and Python drivers. |
| 27 | +* [The custom connection string method](#get-the-mongodb-connection-string-to-customize), for use with other drivers. |
26 | 28 |
|
27 | 29 | ## Prerequisites
|
28 | 30 |
|
29 |
| -- An Azure account. If you don't have an Azure account, create a [free Azure account](https://azure.microsoft.com/free/) now. |
30 |
| -- An Azure Cosmos DB account. For instructions, see [Build a web app using Azure Cosmos DB's API for MongoDB and .NET SDK](create-mongodb-dotnet.md). |
| 31 | +* An Azure account. If you don't have an Azure account, create a [free Azure account](https://azure.microsoft.com/free/) now. |
| 32 | +* An Azure Cosmos DB account. For instructions, see [Quickstart: Azure Cosmos DB for MongoDB driver for Node.js](create-mongodb-dotnet.md). |
31 | 33 |
|
32 | 34 | ## Get the MongoDB connection string by using the quick start
|
33 | 35 |
|
34 | 36 | 1. In an Internet browser, sign in to the [Azure portal](https://portal.azure.com).
|
35 |
| -2. In the **Azure Cosmos DB** blade, select the API. |
36 |
| -3. In the left pane of the account blade, click **Quick start**. |
37 |
| -4. 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](#get-the-mongodb-connection-string-to-customize). |
38 |
| -5. Copy and paste the code snippet into your MongoDB app. |
| 37 | +1. In the **Azure Cosmos DB** pane, select the API. |
| 38 | +1. In the left pane of the account pane, select **Quick start**. |
| 39 | +1. 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](#get-the-mongodb-connection-string-to-customize). |
| 40 | +1. Copy and paste the code snippet into your MongoDB app. |
39 | 41 |
|
40 |
| - :::image type="content" source="./media/connect-account/quickstart-blade.png" alt-text="Quick start blade"::: |
| 42 | + :::image type="content" source="./media/connect-account/quickstart-pane.png" alt-text="Screenshot showing the Quick start pane."::: |
41 | 43 |
|
42 | 44 | ## Get the MongoDB connection string to customize
|
43 | 45 |
|
44 | 46 | 1. In an Internet browser, sign in to the [Azure portal](https://portal.azure.com).
|
45 |
| -2. In the **Azure Cosmos DB** blade, select the API. |
46 |
| -3. In the left pane of the account blade, click **Connection String**. |
47 |
| -4. 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. |
| 47 | +1. In the **Azure Cosmos DB** pane, select the API. |
| 48 | +1. In the left pane of the account pane, select **Connection strings**. |
| 49 | +1. 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. |
48 | 50 |
|
49 |
| - :::image type="content" source="./media/connect-account/connection-string-blade.png" alt-text="Connection String blade" lightbox= "./media/connect-account/connection-string-blade.png" ::: |
| 51 | + :::image type="content" source="./media/connect-account/connection-string-pane.png" alt-text="Screenshot showing the Connection strings pane." lightbox="./media/connect-account/connection-string-pane.png" ::: |
50 | 52 |
|
51 | 53 | ## Connection string requirements
|
52 | 54 |
|
53 |
| -> [!Important] |
| 55 | +> [!IMPORTANT] |
54 | 56 | > Azure Cosmos DB has strict security requirements and standards. Azure Cosmos DB accounts require authentication and secure communication via *TLS*.
|
55 | 57 |
|
56 |
| -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. So, the connection string format is: |
| 58 | +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: |
57 | 59 |
|
58 | 60 | `mongodb://username:password@host:port/[database]?ssl=true`
|
59 | 61 |
|
60 |
| -The values of this string are available in the **Connection String** blade shown earlier: |
| 62 | +The values of this string are: |
61 | 63 |
|
62 | 64 | * Username (required): Azure Cosmos DB account name.
|
63 | 65 | * Password (required): Azure Cosmos DB account password.
|
64 | 66 | * Host (required): FQDN of the Azure Cosmos DB account.
|
65 | 67 | * Port (required): 10255.
|
66 | 68 | * Database (optional): The database that the connection uses. If no database is provided, the default database is "test."
|
67 |
| -* ssl=true (required) |
| 69 | +* ssl=true (required). |
68 | 70 |
|
69 |
| -For example, consider the account shown in the **Connection String** blade. A valid connection string is: |
| 71 | +For example, consider the account shown in the **Connection strings** pane. A valid connection string is: |
70 | 72 |
|
71 | 73 | `mongodb://contoso123:0Fc3IolnL12312asdfawejunASDF@asdfYXX2t8a97kghVcUzcDv98hawelufhawefafnoQRGwNj2nMPL1Y9qsIr9Srdw==@contoso123.documents.azure.com:10255/mydatabase?ssl=true`
|
72 | 74 |
|
73 | 75 | ## Driver Requirements
|
74 | 76 |
|
75 |
| -All drivers that support wire protocol version 3.4 or greater will support Azure Cosmos DB for MongoDB. |
| 77 | +All drivers that support wire protocol version 3.4 or greater support Azure Cosmos DB for MongoDB. |
76 | 78 |
|
77 | 79 | Specifically, 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.
|
78 | 80 |
|
79 | 81 | ## Next steps
|
80 | 82 |
|
81 |
| -- Learn how to [use Studio 3T](connect-using-mongochef.md) with Azure Cosmos DB's API for MongoDB. |
82 |
| -- Learn how to [use Robo 3T](connect-using-robomongo.md) with Azure Cosmos DB's API for MongoDB. |
83 |
| -- Explore MongoDB [samples](nodejs-console-app.md) with Azure Cosmos DB's API for MongoDB. |
84 |
| -- Trying to do capacity planning for a migration to Azure Cosmos DB? You can use information about your existing database cluster for capacity planning. |
85 |
| - - If all you know is the number of vcores and servers in your existing database cluster, read about [estimating request units using vCores or vCPUs](../convert-vcore-to-request-unit.md) |
86 |
| - - If you know typical request rates for your current database workload, read about [estimating request units using Azure Cosmos DB capacity planner](estimate-ru-capacity-planner.md) |
| 83 | +* [Connect to an Azure Cosmos DB account using Studio 3T](connect-using-mongochef.md). |
| 84 | +* [Use Robo 3T with Azure Cosmos DB's API for MongoDB](connect-using-robomongo.md) |
0 commit comments