You are on page 1of 4

How to install and run MongoDB

Go to https://www.mongodb.com/download-center/community
Download the current version of MongoDB Community Server. You can either download
the MSI or ZIP version if you are using Windows 64. MacOS and Linux versions are also
available.
Run the installer once it’s downloaded, and install the ‘Complete’ version.

Choose the ‘Install MongoDB as a Service’ option, and select ‘Run service as a Network
Service user’, leaving all other settings as they are.
You can either allow MongoDB Compass to install, or uncheck this. The tutorial materials
are developed to use Robo3T, but you can also use Studio3T (which has a free 30 day
license) or MongoDB Compass should be very similar.
Once installed, you will need to open a ‘Command Prompt’ window, and find the location of
the MongoDB installation. If you accepted the default, then on Windows, you should find it
in:
C:\Program Files\MongoDB\Server\x.y\bin (where x.y is the version
number of MongoDB server that you have installed).

In this folder you will find a number of commands:


mongod.exe – this command starts the server

mongo.exe – this command will open a shell connection.

To start, you need to start the server. Type:


mongod

To start the server. You must run the commands directly from a command prompt, and be
within the directory where it is installed.
Now you will need to open a second window if you wish to use the shell connection to
MongoDB.
Type:
mongo

And it should be connected to your server. Test by creating and retrieving from a collection.
To exit your mongo session type exit.

To close down the server type CTRL+C into the command window where the server is
running.
To use Robo3T, you should download and install it.
You can download it from https://robomongo.org/
Once installed, create a connection. Click on Connect… in the File menu (or type
CTRL+N):

In the connection window, select Create:


Give the connection a name, e.g. Localhost, leave the Address as localhost and the port as
27017. Do not change any other settings, and click ‘Test’ to test your connection. You
should get a successful test as below:

If not, it is likely that you have not started the MongoDB server. Use the previous
instructions to ensure the server is running.
Once the test has been successful, close the message window, select Save, and then click
Connect in the Connection Manager window to connect to your new instance.

You might also like