How to connect an existing MongoDB® Database Instance to a Private Network
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.
Before you start
To complete the actions presented below, you must have:
- A Scaleway account logged into the console
- Owner status or IAM permissions allowing you to perform actions in the intended Organization
- A valid API key
- A Managed MongoDB® Database Instance
How to attach a Database Instance to a Private Network
- Click MongoDB® under Databases on the side menu. A list of your Database Instances displays.
- Click the database name or more icon, then click More info to access the Database Instance information page.
- Scroll to the Network section.
- Click Attach Private Network next to Private endpoint. A pop-up appears.
- Choose one or both of the options below:
- Select and attach an existing Private Network and select the network from the drop-down list.
- Create and attach a new Private Network and enter the name of the network in the form.
- Click Attach to Private Network to conclude.
How to connect to a Database Instance through a Public Gateway
If you want to connect locally to a Database Instance that is not accessible via the public internet, you can use SSH Bastion and connect it to the same Private Network the Database Instance is connected to.
-
Open an SSH tunnel with port forwarding:
ssh -L local_port:instance_id.network_id.internal:27017 bastion@gatewayIP -p 61000 -N
-
Connect using
mongosh
:mongosh --host localhost --port local_port --username "username"
How to detach a Database Instance from a Private Network
- Click MongoDB® under Databases on the side menu. A list of your Database Instances displays.
- Click the database name or more icon, then click More info to access the Database Instance information page.
- Scroll to the Network section.
- Click Detach Private Network. A pop-up appears.
- Click Detach resource to confirm.