By AI-LastWish
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?
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!
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:
Before proceeding, it’s crucial to secure your MongoDB instance:
mongod.conf to enable security.authorization.27017) to known IP addresses. Use DigitalOcean’s Cloud Firewall service to restrict access to your Droplet’s MongoDB port.Once your MongoDB has been configured for remote access, you can connect using Compass as normal:
mongodb://<user>:<password>@<droplet-ip>:27017/<database>?authSource=admin
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.