Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ Managed Databases for PostgreSQL and MySQL are currently not compatible with the
You can use Public Gateways in [SSH bastion](/public-gateways/how-to/use-ssh-bastion/) mode and perform port forwarding.
</Message>

<Message type="tip">
If you are using Scaleway Kubernetes Kapsule, you can use the [scaleway-k8s-vpc](https://github.com/Sh4d1/scaleway-k8s-vpc) GitHub project to connect a Database Instance to your pods using a Private Network.<br /><br />
Once your Kapsule node is connected to the Private Network you can directly reach the database by using the assigned service IP. There is no need to expose it through a Kubernetes resource like a service. The database is ready to use out of the box. <br /><br />
**The `scaleway-k8s-vpc` is not an officially supported by Scaleway.**
</Message>

## How to detach a Database Instance from a Private Network

1. Click **PostgreSQL and MySQL** under **Managed Databases** on the side menu. A list of your Database Instances displays.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
meta:
title: How to connect to a MongoDB® Database Instance
title: How to connect to a Managed MongoDB® Database Instance
description: This page explains how to connect to a MongoDB® Database Instance
content:
h1: How to connect to a MongoDB® Database Instance
h1: How to connect to a Managed MongoDB® Database Instance
paragraph: This page explains how to connect to a MongoDB® Database Instance
tags: mongodb mongodb document database-instance managed-database database
dates:
validation: 2024-09-18
validation: 2024-02-17
posted: 2024-09-18
categories:
- managed-databases
Expand All @@ -19,7 +19,6 @@ Managed MongoDB® is currently in public beta. Click [here](https://www.scaleway

<Macro id="requirements" />


- A Scaleway account logged into the [console](https://console.scaleway.com)
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization
- A [MongoDB® Database Instance](/managed-mongodb-databases/quickstart/)
Expand All @@ -38,7 +37,7 @@ Managed MongoDB® is currently in public beta. Click [here](https://www.scaleway

Find below a detailed description of each connection mode:

### mongosh
### With mongosh

To connect to a public endpoint using the MongoDB® shell:

Expand Down Expand Up @@ -67,19 +66,11 @@ If the connection is successful, you should see the following message display on
rs-{db-instance-id} [primary] test>
```

Follow the same procedure to connect to a private endpoint for one node, replacing `{privateNetworkId}` with the `ID` of your Private Network:

```sh
mongosh "mongodb://{db-instance-id}-0.{privateNetworkId}" -u {username} --tlsCAFile {your_certificate.pem}
```

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:

```sh
"mongodb://{db-instance-id}-0.{privateNetworkId},{db-instance-id}-1.{privateNetworkId},{db-instance-id}-2.{privateNetworkId}" -u {username} --tlsCAFile {your_certificate.pem}
```
<Message type="important">
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.
</Message>

### Python
### With Pymongo

The following code shows you how to use the `pymongo` library to connect using TLS.

Expand Down Expand Up @@ -115,8 +106,11 @@ documents = collection.find({})
for doc in documents:
print(doc)
```
<Message type="important">
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.
</Message>

### Node.js
### With Node.js

The following code shows you how to use the `mongodb` module to connect using TLS.

Expand Down Expand Up @@ -170,7 +164,7 @@ async function run() {
run().catch(console.dir);
```

### Go
### With Go

The following code shows you how to use the `mongo` driver to connect using TLS.
```go
Expand Down Expand Up @@ -225,7 +219,7 @@ type Car struct {
}
```

### Mongoose
### With Mongoose

The following code shows you how to use the `Mongoose` schema to connect using TLS.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
meta:
title: How to connect a Managed MongoDB® Database Instance to a Private Network
description: Instructions for connecting your MongoDB® Database Instance over a Private Network.
content:
h1: How to connect a Managed MongoDB® Database Instance to a Private Network
paragraph: Instructions for connecting your MongoDB® Database Instance over a Private Network.
tags: managed-mongodb mongodb private-network database-instance
dates:
validation: 2025-02-17
posted: 2025-02-17
categories:
- managed-databases
- mongodb
---

[Private Networks](/vpc/concepts/#private-networks) allows you to enhance the security of your system's architecture by isolating it from the internet.

Using Private Networks improves performance by reducing the latency between your application and your database nodes. It also increases the security of your databases, as Instances in your Private Network can directly communicate with your Database Instance, without passing through the public internet.

You can create new Database Instances to attach to your Private Network, or attach existing ones.

<Macro id="requirements" />

- A Scaleway account logged into the [console](https://console.scaleway.com)
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization
- A valid [API key](/iam/how-to/create-api-keys/)
- A [Managed MongoDB® Database Instance](/managed-mongodb-databases/how-to/create-a-database-instance)

## How to attach a Database Instance to a Private Network

<Message type="note">
You can only attach your Database Instance to one Private Network at a time.
</Message>

1. Click **MongoDB®** under **Managed Databases** on the side menu. A list of your Database Instances displays.
2. Click the database name or <Icon name="more" /> > **More info** to access the Database Instance information page.
3. Scroll to the **Network** section.
4. Click **Attach Private Network** next to **Private endpoint**. A pop-up appears.
5. Choose whether to:
- Select and attach an existing Private Network and select the network from the drop-down list.
<Message type="important">
The Database Instance must be attached to a Private Network in the same region.
</Message>
- Create and attach a new Private Network and enter the name of the network in the form.
<Message type="important">
If you select this option, a Private Network with default settings will be created in the same region as your Database Instance. Do not use a TLD (e.g. dev, cloud) as a name, to avoid conflicts.
</Message>
6. Click **Attach to Private Network** to conclude.

<Message type="important">
Managed MongoDB® is currently not compatible with the [Static NAT](/public-gateways/concepts/#nat) feature of [Scaleway Public Gateways](/public-gateways/concepts/#public-gateway). You can use Public Gateways in [SSH bastion](/public-gateways/how-to/use-ssh-bastion/) mode and perform port forwarding.
</Message>

<Message type="tip">
Once you have attached your Database Instance to a Private Network, you can [connect to the Database Instance](/managed-mongodb-databases/how-to/connect-database-instance) using the private endpoint connection string.
</Message>

## How to detach a Database Instance from a Private Network

1. Click **MongoDB®** under **Managed Databases** on the side menu. A list of your Database Instances displays.
2. Click the database name or <Icon name="more" /> > **More info** to access the Database Instance information page.
3. Scroll to the **Network** section.
4. Click <Icon name="unlink" /> next to the static IP that you want to unlink from your Database Instance.
5. Click **Detach Private Network** to remove the Instance from your Private Network.

<Message type="note">
This action takes a few moments to complete. During this time, your Database Instance:
- remains available,
- goes into **Configuring** mode, and
- network configuration actions become unavailable
</Message>
Loading