Question

How to access MongoDB inside a Volume Block Storage via MongoDB Compass?

I want to access MongoDB inside a Volume Block Storage via MongoDB Compass to manage my production database.

Below is my volume list

nguyenquangtri@Nguyens-Mac-mini ~ % doctl compute volume list

ID                                      Name                                        Size     Region    Filesystem Type    Filesystem Label    Droplet IDs    Tags

fb61a5fb-c586-11ee-8cf4-0a58ac14a3ab    pvc-0c11ec25-ed80-4113-bf84-9b6ef03780f7    1 GiB    sgp1      ext4                                   [399862184]    k8s:f5f9b710-cf3b-4071-93e5-87aadb5ce09a

fc3a2990-c586-11ee-a9f0-0a58ac14a476    pvc-8dc047a6-07a9-4604-a654-6c441305c626    1 GiB    sgp1      ext4                                   [399862182]    k8s:f5f9b710-cf3b-4071-93e5-87aadb5ce09a

f9ba7163-c586-11ee-8cf4-0a58ac14a3ab    pvc-f865999f-7f33-44ec-8a3b-ecdc20f17427    1 GiB    sgp1      ext4                                   [399862183]    k8s:f5f9b710-cf3b-4071-93e5-87aadb5ce09a

fd664b83-c586-11ee-a4ec-0a58ac14a32f    pvc-ff2592bf-9330-49e9-95aa-495d8db620d2    1 GiB    sgp1      ext4                                   [399862182]    k8s:f5f9b710-cf3b-4071-93e5-87aadb5ce09a

So how can I do that?


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
February 11, 2024

Hi there,

To access MongoDB hosted on a Volume Block Storage via MongoDB Compass, you need to ensure that MongoDB is correctly set up and accessible over the network, and your Volume is attached to a specific Droplet in DigitalOcean.

From your doctl volume list, it seems you have your volumes set up and attached to Droplets.

The volumes you’ve listed are using ext4, which is a filesystem type. For MongoDB to run on these volumes, you must have MongoDB installed on a Droplet that has access to these volumes. Make sure MongoDB data directories are correctly set to use the mounted volume paths.

By default, MongoDB binds to localhost (127.0.0.1). To access it remotely (e.g., via MongoDB Compass), you need to edit the MongoDB configuration file (mongod.conf) to listen on an external interface. You can do this by setting the bindIp option under net to 0.0.0.0 (to listen on all interfaces) or to the specific IP address of your Droplet’s network interface.

Example:

net:
  port: 27017
  bindIp: 0.0.0.0  # Listen on all interfaces

Warning: Exposing MongoDB to the internet can pose significant security risks. Ensure you secure MongoDB access using authentication and firewall rules.

Here is a step by step tutorial on how to usually configure this:

https://www.digitalocean.com/community/tutorials/how-to-configure-remote-access-for-mongodb-on-ubuntu-20-04

Before proceeding, it’s crucial to secure your MongoDB instance:

  • Enable Authentication: Edit mongod.conf to enable security.authorization.
  • Firewall Configuration: Limit access to MongoDB’s port (default 27017) to known IP addresses. Use DigitalOcean’s Cloud Firewall service to restrict access to your Droplet’s MongoDB port.
  • Create MongoDB Users: Create user accounts with the necessary privileges for database access.

Once your MongoDB has been configured for remote access, you can connect using Compass as normal:

  • Install MongoDB Compass: Download and install MongoDB Compass on your local machine.
  • Connection String: Use the connection string format to connect MongoDB Compass to your MongoDB instance. The format is generally:
    mongodb://<user>:<password>@<droplet-ip>:27017/<database>?authSource=admin
    
  • Input Connection Details: Open MongoDB Compass and input your connection details based on the above format.

An alternative option here is to use a Managed MongoDB cluster instead which will simplify the operational side of things for you:

https://www.digitalocean.com/products/managed-databases-mongodb

Hope that this helps!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel