|
1 | 1 | ---
|
2 |
| -title: Use Mongo Shell to connect |
3 |
| -titleSuffix: Azure Cosmos DB for MongoDB vCore |
4 |
| -description: Connect to an Azure Cosmos DB for MongoDB vCore account using Mongo Shell community tool to query data. |
| 2 | +title: Use MongoDB Shell to connect |
| 3 | +titleSuffix: Azure Cosmos DB for MongoDB in vCore architecture |
| 4 | +description: Connect to an Azure Cosmos DB for MongoDB (vCore architecture) account by using the MongoDB Shell community tool to query data. |
5 | 5 | author: kruti-m
|
6 | 6 | ms.author: krmeht
|
7 | 7 | ms.reviewer: yongl
|
8 | 8 | ms.service: cosmos-db
|
9 | 9 | ms.subservice: mongodb-vcore
|
10 | 10 | ms.topic: how-to
|
11 | 11 | ms.date: 02/05/2024
|
12 |
| -# CustomerIntent: As a database owner, I want to use Mongo Shell to connect and query my database & collections. |
| 12 | +# customer intent: As a database owner, I want to use Mongo Shell to connect to and query my database and collections. |
13 | 13 | ---
|
14 | 14 |
|
15 |
| -# Use MongoDB Shell (Mongosh) to connect to Azure Cosmos DB for MongoDB vCore |
| 15 | +# Use MongoDB Shell to connect to Azure Cosmos DB for MongoDB (vCore) |
16 | 16 |
|
17 | 17 | [!INCLUDE[MongoDB vCore](~/reusable-content/ce-skilling/azure/includes/cosmos-db/includes/appliesto-mongodb-vcore.md)]
|
18 | 18 |
|
19 |
| -MongoDB Shell (Mongosh), is a JavaScript and Node.js environment for interacting with MongoDB deployments. It's a popular community tool to test queries and interact with the data in your Azure Cosmos DB for MongoDB database. |
| 19 | +MongoDB Shell (`mongosh`) is a JavaScript and Node.js environment for interacting with MongoDB deployments. It's a popular community tool to test queries and interact with the data in your Azure Cosmos DB for MongoDB database. |
20 | 20 |
|
21 | 21 | ## Prerequisites
|
22 |
| -Here are some prerequisites. |
23 |
| -- An existing Azure Cosmos DB for MongoDB vCore cluster. |
24 |
| -- An installed version of the MongoShell from the community site. |
25 |
| -- Ensure you're setting up the necessary environment variables post installation for your operating system |
26 |
| -- Ensure the firewall settings to allow the machine to connect. Follow the guidelines for [configuring the firewall for Azure Cosmos DB](../../../cosmos-db/how-to-configure-firewall.md) |
27 |
| - - You can choose to allow requests from your current IP, requests from cloud services or requests from virtual machines - specific IP Ranges |
28 |
| - |
29 |
| - |
30 | 22 |
|
31 |
| -If you accidentally open all the ports, you're warned before saving the changes. |
| 23 | +- An existing Azure Cosmos DB for MongoDB (vCore architecture) cluster. |
| 24 | +- An installed version of MongoDB Shell from the community site. |
| 25 | +- Setup of the necessary post-installation environment variables for your operating system. |
| 26 | +- Firewall settings that allow the machine to connect. Follow the guidelines for [configuring the firewall for Azure Cosmos DB](../../../cosmos-db/how-to-configure-firewall.md). |
| 27 | + |
| 28 | + You can choose to allow requests from your current IP address, requests from cloud services, or requests from virtual machines (specific IP ranges). |
32 | 29 |
|
33 |
| -## Connect using Mongo Shell (Mongosh) |
| 30 | +  |
34 | 31 |
|
35 |
| -To add your Azure Cosmos DB cluster to Mongo shell, perform the following steps: |
36 |
| -1. Retrieve the connection information for your Azure Cosmos DB for MongoDB vCore using the instructions [here](quickstart-portal.md#get-cluster-credentials). |
| 32 | + If you accidentally open all the ports, you're warned before you save the changes. |
37 | 33 |
|
38 |
| - |
39 |
| -Once you have the connection string, you can either |
40 |
| -- Have the shell prompt you to enter the password or |
41 |
| -- Provide the password as a part of the connection string |
| 34 | +## Connect by using MongoDB Shell |
42 | 35 |
|
43 |
| -2. Connect using Mongo Shell |
| 36 | +To add your Azure Cosmos DB cluster to MongoDB Shell, perform the following steps: |
44 | 37 |
|
45 |
| -**A. By entering the password in the MongoShell Prompt** |
| 38 | +1. Retrieve the connection information for your Azure Cosmos DB for MongoDB (vCore) instance by using [these instructions](quickstart-portal.md#get-cluster-credentials). |
46 | 39 |
|
| 40 | +  |
47 | 41 |
|
48 |
| -Your connection string would look like this: |
49 |
| - ``` |
50 |
| - "mongodb+srv://<username>@<servername>.mongocluster.cosmos.azure.com/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000" |
51 |
| - ``` |
52 |
| -Here's an example of how the command looks like: |
53 |
| - ``` |
54 |
| - mongosh "mongodb+srv:// [email protected]/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000 |
55 |
| - ``` |
56 |
| - |
| 42 | +2. Connect by using either of these methods: |
57 | 43 |
|
58 |
| -Once you provide the password and are successfully authenticated, you notice some warning. It states *"This server or service appears to be an emulation of MongoDB"*. |
59 |
| -The warning can be ignored. It's the shell's way of notifying that you aren't connection to an emulation of MongoDB. When, it's an Azure as a platform as a service offering it's expected. |
| 44 | + - Enter the password in the Mongo Shell prompt. Your connection string looks like this example: |
60 | 45 |
|
61 |
| -**B. By providing the password as a part of the connection string** |
| 46 | + ``` |
| 47 | + "mongodb+srv://<username>@<servername>.mongocluster.cosmos.azure.com/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000" |
| 48 | + ``` |
62 | 49 |
|
63 |
| -Alternately you can also use a connection string with the password in which case the format looks something like this. |
64 |
| -``` |
65 |
| -mongosh "mongodb+srv://<SERVERNAME>.mongocluster.cosmos.azure.com/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000" --username "<USER>" -password "<PASSWORD>" |
66 |
| -``` |
| 50 | + The command looks like this example: |
67 | 51 |
|
68 |
| -Here's an example of how the command looks like: |
69 |
| -``` |
70 |
| - mongosh "mongodb+srv://mongodbvcoretesting.mongocluster.cosmos.azure.com/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000" --username "testuser" -password "******" |
71 |
| -``` |
72 |
| - |
| 52 | + ``` |
| 53 | + mongosh "mongodb+srv://[email protected]/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000 |
| 54 | + ``` |
| 55 | +
|
| 56 | +  |
| 57 | +
|
| 58 | + After you provide the password and are successfully authenticated, this warning appears: "This server or service appears to be an emulation of MongoDB." You can ignore it. This warning is generated because the connection string contains `cosmos.azure`. Azure Cosmos DB is a native Azure platform as a service (PaaS) offering. |
| 59 | +
|
| 60 | + - Provide the password as a part of the connection string. The format looks something like this example: |
| 61 | +
|
| 62 | + ``` |
| 63 | + mongosh "mongodb+srv://<SERVERNAME>.mongocluster.cosmos.azure.com/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000" --username "<USER>" -password "<PASSWORD>" |
| 64 | + ``` |
| 65 | +
|
| 66 | + The command looks like this example: |
| 67 | +
|
| 68 | + ``` |
| 69 | + mongosh "mongodb+srv://mongodbvcoretesting.mongocluster.cosmos.azure.com/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000" --username "testuser" -password "******" |
| 70 | + ``` |
| 71 | +
|
| 72 | +  |
73 | 73 |
|
74 | 74 | ## Next step
|
75 | 75 |
|
|
0 commit comments