You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Create a new cluster and its replica in another region
32
32
33
33
Create a MongoDB cluster with a cluster read replica in another region by using Azure Cosmos DB for MongoDB vCore.
34
34
@@ -116,25 +116,105 @@ You can also select add 0.0.0.0 - 255.255.255.255 firewall rule to allow not jus
116
116
117
117
:::image type="content" source="media/quickstart-portal/deployment-complete.png" alt-text="Screenshot of the deployment page for a cluster.":::
118
118
119
-
## Connect to the cluster and ingest data
119
+
## Connect to primary cluster and ingest data
120
120
121
121
Get the connection string you need to connect to this primary cluster using your application code.
122
122
123
123
1. From the Azure Cosmos DB for MongoDB vCore primary cluster page, select the **Connection strings** navigation menu option under **Settings**.
124
124
125
125
:::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.":::
126
126
127
-
1.Record the value from the **Connection string** field.
127
+
1.Copy the value from the **Connection string** field.
128
128
129
129
> [!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.
131
131
132
132
1. In MongoDB shell, connect to the primary cluster using the connection string.
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.
0 commit comments