MongoDB - Java

MongoDB - PHP

MongoDB - Advanced

MongoDB - Useful Resources

MongoDB - Environment



Let us now see how to install MongoDB on Windows.

Install MongoDB On Windows

To install MongoDB on Windows, first download the latest release of MongoDB from https://www.mongodb.com/try/download/community.

Enter the required details, choose the version of MongoDB, operating system and, packaging as:

Mongodb Community

Now install the downloaded file, by default, it will be installed in the folder C:\Program Files\MongoDB.

By default, MongoDB will be installed as a Service and Installer downloads and installs MongDB Compass as a default GUI (Graphical User Interface).

Once MongoDB server and MongoDB Compass are installed, you can open MongoDB Compass and use the following connectio string to connect to locally installed MongoDB Server.

mongodb://localhost:27017/

Using MongoDB Shell

MongoDB Shell is a Command Line Tool and is a quickest way to connect to MongoDB. It is a standalone tool from MongoDB Server and is open source licensed under Apache 2.0.

Download MongoDB shell using https://www.mongodb.com/try/download/shell.

Mongodb Shell

We've downloaded mongosh-2.5.10-win32-x64.zip and extracted it to D:\mongosh-2.5.10-win32-x64 folder. Open mongosh application from D:\mongosh-2.5.10-win32-x64\bin folder. It will open a command prompt which initially prompt to connect to local mongodb instance.

D:\mongosh-2.5.10-win32-x64\bin>mongosh
Current Mongosh Log ID: 6969f1784daa1172e11e2620
Connecting to:          mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.5.10
Using MongoDB:          8.2.3
Using Mongosh:          2.5.10
mongosh 2.6.0 is available for download: https://www.mongodb.com/try/download/shell

For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/

------
   The server generated these startup warnings when booting
   2026-01-12T12:37:51.203+05:30: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
------

test>

Install MongoDB on Ubuntu

Run the following command to import the MongoDB public GPG key −

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

Create a /etc/apt/sources.list.d/mongodb.list file using the following command.

echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' 
   | sudo tee /etc/apt/sources.list.d/mongodb.list

Now issue the following command to update the repository −

sudo apt-get update

Next install the MongoDB by using the following command −

apt-get install mongodb-10gen = 8.2.3

In the above installation, 8.2.3 is currently released MongoDB version. Make sure to install the latest version always. Now MongoDB is installed successfully.

Start MongoDB

sudo service mongodb start

Stop MongoDB

sudo service mongodb stop

Restart MongoDB

sudo service mongodb restart

To use MongoDB run the following command.

mongo

This will connect you to running MongoDB instance.

MongoDB Help

To get a list of commands, type db.help() in MongoDB client. This will give you a list of commands as shown in the following screenshot.

DB Help

MongoDB Statistics

To get stats about MongoDB server, type the command db.stats() in MongoDB client. This will show the database name, number of collection and documents in the database. Output of the command is shown in the following screenshot.

DB Stats
Advertisements