By Viet Tran
I want to create a MongoDB server and connect it from local machine using Spring Data MongoDB. I’m able to connect to MongoDB using ssh via Mac CLI but don’t know how to create URI to connect to it. In another words, I don’t know how to create MongoClient.
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!
Accepted Answer
Hi @devbc7ce689810e2095410142c
I would recommend that you keep MongoDB on your droplet contained, so it only listens on localhost of the droplet - and not exposing it to the internet.
Then you can create a SSH tunnel to your server and you would then connect to localhost on your computer in Spring Data.
This tutorial is for various other services and ports, but you just need to setup port 27017 which is MongoDB’s default port (unless you’ve changed that):
https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-tunneling-on-a-vps
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.