Running MongoDB Community Edition on Ubuntu server?

I try to make my question as clear as possible. So I created a free tier of MongoDB Cluster. It was a cool experience. I decided to Install an instance of Community Edition on an Ubuntu server. It worked and I can enter the shell by mongo command. It shows some warnings, though. I created some empty collections there.
The point is I was using the free tier in a Node.JS Express app through a URI string provided by MongoDB Cluster. I also was able to browse my collections through Compass GUI via a similar URI string.
But how can I connect my app to my MongoDB which is installed on Ubuntu server? And how to browse its collections through Compass?
Thanks for your help.

Hi @mj69, and welcome to the MongoDB Community forums! :wave:

You would connect to your MongoDB instance in a similar fashion. If your application and MongoDB instance are running on the same server, then your connection string would be mongodb://localhost:27017. If the application and MongoDB instance are on different servers then the connection string would be mongodb://hostname:27017.

In the above examples I’m assuming you started the mongod process on the default port of 27017. If you chose a different port, then you would need to change that. I’m also assuming one of the warning you are getting is similar to the following:

2022-10-05T09:37:09.126-06:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted

If you did enable authorization, then you would need to pass your credentials in similar to how you did with your Atlas connection.

Let us know if you have any other questions.


Thank you @Doug_Duncan for your response.
Since I’m very new to this topic of working with MongoDB on a remote Virtual Private Server, things are a bit more complicated than that on my side.

Yes, my Node.JS app and MongoDB Community Edition are both on a remote Ubuntu server.
I remember when working with MongoDB on my local Windows 10 machine, I had to activate it with mongod, first. Only then I could enter the Mongo shell in another PowerShell instance with mongo.

A. What if my website’s end users want to add or remove data to and from my in-server database? Will the server keep mongod command active even if I don’t do that? Is such thing even necessary in this scenario?

This article says I have to use the IP address of my remote server hosting MongoDB when trying to connect to it (from for example a Win10 machine) when using Compass:
I’ve changed the bind_ip to in /etc/mongodb.conf

B. Is this URI string correct for connecting Compass to the remote server db:

mongodb://<IP address of ubuntu server>:27017/?tls=true

I used this URI string in my app when using the MongoDB cluster:
mongodb+srv://<username>:<password>@<some address>

C. Where is the username and password when MongoDB is installed on a remote server? Do I have to create them in Mongo shell on the remote server? If yes, then how?

D. Does creating a user on in-server database change the URI string for Compass? Does it have something to do with Authentication Method section in Compass?

E. In absence of such user, can Compass access the in-server db directly?

I know that’s a lot. I appreciate your help.

Hi @mj69,

I see this follow up question was also posted and addressed via Connecting a remote server to Compass?.


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.