Skip to content

Commit 61e5606

Browse files
committed
Cluster replica part v1
1 parent 6fd7acc commit 61e5606

File tree

2 files changed

+86
-6
lines changed

2 files changed

+86
-6
lines changed
Loading

articles/cosmos-db/mongodb/vcore/quickstart-cross-region-replica-portal.md

Lines changed: 86 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ In this quickstart, you create a cluster replica in another region for an Azure
2828
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free).
2929
- [MongoDB shell](https://www.mongodb.com/try/download/shell)
3030

31-
## Create a cluster replica for a new cluster
31+
## Create a new cluster and its replica in another region
3232

3333
Create a MongoDB cluster with a cluster read replica in another region by using Azure Cosmos DB for MongoDB vCore.
3434

@@ -116,25 +116,105 @@ You can also select add 0.0.0.0 - 255.255.255.255 firewall rule to allow not jus
116116

117117
:::image type="content" source="media/quickstart-portal/deployment-complete.png" alt-text="Screenshot of the deployment page for a cluster.":::
118118

119-
## Connect to the cluster and ingest data
119+
## Connect to primary cluster and ingest data
120120

121121
Get the connection string you need to connect to this primary cluster using your application code.
122122

123123
1. From the Azure Cosmos DB for MongoDB vCore primary cluster page, select the **Connection strings** navigation menu option under **Settings**.
124124

125125
:::image type="content" source="media/quickstart-cross-region-replication/select-connection-strings-option.png" alt-text="Screenshot of the connection strings page in the cluster propteries.":::
126126

127-
1. Record the value from the **Connection string** field.
127+
1. Copy the value from the **Connection string** field.
128128

129129
> [!IMPORTANT]
130-
> The connection string in the portal does not include the username and password values. You must replace the `<user>` and `<password>` placeholders with the credentials you entered when you created the cluster.
130+
> The connection string in the portal does not include the username and password values. You must replace the `<user>` and `<password>` placeholders with the credentials you entered when you created the cluster.
131131
132132
1. In MongoDB shell, connect to the primary cluster using the connection string.
133133

134-
```Mongo Shell
135-
mongosh mongodb+srv://`<user>`@`<cluster_name>`.mongocluster.cosmos.azure.com/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000
134+
```cmd
135+
mongosh mongodb+srv://<user>@<cluster_name>.mongocluster.cosmos.azure.com/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000
136136
```
137137

138+
1. Create a *my_script.js* script file to run from the MongoDB shell. This script file creates two collections and inserts documents with data into those collections.
139+
140+
```JavaScript
141+
let dogDocs = [
142+
{
143+
name: "pooch",
144+
breed: "poodle",
145+
weight: "6 lbs"
146+
},
147+
{
148+
name: "mutt",
149+
breed: "bulldog",
150+
weight: "10 lbs"
151+
}
152+
];
153+
154+
let catDocs = [
155+
{
156+
name: "minni",
157+
breed: "persian",
158+
color: "white"
159+
},
160+
{
161+
name: "tinkle",
162+
breed: "bombay",
163+
color: "black"
164+
}
165+
];
166+
167+
let dogIndex = { name : 1 };
168+
let catIndex = { name : 1 };
169+
170+
let collInfoObjs = [
171+
{ coll: "dogs", data: dogDocs, index: dogIndex },
172+
{ coll: "cats", data: catDocs, index: catIndex }
173+
];
174+
175+
for (obj of collInfoObjs) {
176+
db[obj.coll].insertMany(obj.data);
177+
db[obj.coll].createIndex(obj.index);
178+
}
179+
```
180+
181+
1. Run the script from the MongoDB shell.
182+
183+
```MongoDB Shell
184+
load(my_script.js);
185+
```
186+
187+
1. In the MongoDB shell, read data from the database.
188+
189+
```MongoDB Shell
190+
db.dogs.find();
191+
db.cats.find();
192+
```
193+
194+
## Connect to read replica cluster in another region and read data
195+
196+
Get the connection string for the read cluster replica in another region.
197+
198+
1. From the Azure Cosmos DB for MongoDB vCore *primary* cluster page, select the **Global distribution (preview)** page under **Settings**.
199+
200+
:::image type="content" source="media/quickstart-cross-region-replication/global-distribution-page-on-primary-cluster.png" alt-text="Screenshot of the global distribution preview page in the primary cluster propteries.":::
201+
202+
1. Select the cluster replica name to open the read cluster replica properties in the Azure portal.
203+
204+
1. On the replica cluster sidebar, under **Cluster management**, select **Connection strings**.
205+
206+
1. Copy the value from the **Connection string** field.
207+
208+
> [!IMPORTANT]
209+
> The connection string in the portal does not include the username and password values. You must replace the `<user>` and `<password>` placeholders with the credentials you entered when you created the cluster.
210+
211+
1. In MongoDB shell, connect to the read replica cluster using its connection string.
212+
213+
```cmd
214+
mongosh mongodb+srv://<user>@<cluster_replica_name>.mongocluster.cosmos.azure.com/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000
215+
```
216+
217+
138218
## Clean up resources
139219

140220
When you're done with Azure Cosmos DB for MongoDB vCore cluster, you can delete the Azure resources you created so you don't incur more charges.

0 commit comments

Comments
 (0)