|
7 | 7 | paragraph: This page explains how to connect to a MongoDB® Database Instance |
8 | 8 | tags: mongodb mongodb document database-instance managed-database database |
9 | 9 | dates: |
10 | | - validation: 2024-09-18 |
| 10 | + validation: 2024-02-17 |
11 | 11 | posted: 2024-09-18 |
12 | 12 | categories: |
13 | 13 | - managed-databases |
@@ -38,7 +38,7 @@ Managed MongoDB® is currently in public beta. Click [here](https://www.scaleway |
38 | 38 |
|
39 | 39 | Find below a detailed description of each connection mode: |
40 | 40 |
|
41 | | -### mongosh |
| 41 | +### With mongosh |
42 | 42 |
|
43 | 43 | To connect to a public endpoint using the MongoDB® shell: |
44 | 44 |
|
@@ -67,19 +67,11 @@ If the connection is successful, you should see the following message display on |
67 | 67 | rs-{db-instance-id} [primary] test> |
68 | 68 | ``` |
69 | 69 |
|
70 | | -Follow the same procedure to connect to a private endpoint for one node, replacing `{privateNetworkId}` with the `ID` of your Private Network: |
71 | | - |
72 | | - ```sh |
73 | | - mongosh "mongodb://{db-instance-id}-0.{privateNetworkId}" -u {username} --tlsCAFile {your_certificate.pem} |
74 | | - ``` |
75 | | - |
76 | | -For multiple nodes, replace `{db-instance-id}` with the Database Instance UUID of each respective Instance, and `{privateNetworkId}` with the `ID` of your Private Network: |
77 | | - |
78 | | - ```sh |
79 | | - "mongodb://{db-instance-id}-0.{privateNetworkId},{db-instance-id}-1.{privateNetworkId},{db-instance-id}-2.{privateNetworkId}" -u {username} --tlsCAFile {your_certificate.pem} |
80 | | - ``` |
| 70 | +<Message type="important"> |
| 71 | +To connect to a MongoDB® via a Private Network, use the following command: `mongosh "mongodb+srv://{username}:{password}@{instance_id}.{private_network_id}.internal/?tls=true&tlsCAFile={tls_certificate}"`. Make sure you replace the variables indicated within the `{}` with their corresponding values. |
| 72 | +</Message> |
81 | 73 |
|
82 | | -### Python |
| 74 | +### With Pymongo |
83 | 75 |
|
84 | 76 | The following code shows you how to use the `pymongo` library to connect using TLS. |
85 | 77 |
|
@@ -115,8 +107,11 @@ documents = collection.find({}) |
115 | 107 | for doc in documents: |
116 | 108 | print(doc) |
117 | 109 | ``` |
| 110 | +<Message type="important"> |
| 111 | +To connect to a MongoDB® via a Private Network, use the following connection string: `connection_string = f"mongodb+srv://{username}:{password}@{instance_id}.{private_network_id}.internal/?tls=true&tlsCAFile={tls_certificate}"`. Make sure you replace the variables indicated within the `{}` with their corresponding values. |
| 112 | +</Message> |
118 | 113 |
|
119 | | -### Node.js |
| 114 | +### With Node.js |
120 | 115 |
|
121 | 116 | The following code shows you how to use the `mongodb` module to connect using TLS. |
122 | 117 |
|
@@ -170,7 +165,7 @@ async function run() { |
170 | 165 | run().catch(console.dir); |
171 | 166 | ``` |
172 | 167 |
|
173 | | -### Go |
| 168 | +### With Go |
174 | 169 |
|
175 | 170 | The following code shows you how to use the `mongo` driver to connect using TLS. |
176 | 171 | ```go |
@@ -225,7 +220,7 @@ type Car struct { |
225 | 220 | } |
226 | 221 | ``` |
227 | 222 |
|
228 | | -### Mongoose |
| 223 | +### With Mongoose |
229 | 224 |
|
230 | 225 | The following code shows you how to use the `Mongoose` schema to connect using TLS. |
231 | 226 |
|
|
0 commit comments