Mongo DB works with raw TCP instead of HTTP so we need create stream
with Nginx.
Add the below code above http
block in nginx config file (eg: /etc/nginx/nginx.conf
for Ubuntu)
stream {
server {
listen 9999;
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass stream_mongo_backend;
}
upstream stream_mongo_backend {
server localhost:27017;
}
}
The file after modified look like this:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
....
}
stream {
server {
listen 9999;
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass stream_mongo_backend;
}
upstream stream_mongo_backend {
server localhost:27017;
}
}
http {
...
}
...
Here you can share your Mongo DB server to your friend with: yourip:9999
What about connecting to MongoDB Atlas with Username and Password?