0% found this document useful (0 votes)
8 views

Install MongoDB

Uploaded by

ariankhatib2
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Install MongoDB

Uploaded by

ariankhatib2
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Download and Install MongoDB

Download
Go to the following link to download the MongoDB:
https://www.mongodb.com/download-center/community

By default, The “MongoDB Community Server” is selected, if not, select ““MongoDB


Community Server” option.
Choose you OS. For Windows, choose “Windows X64” and click on “Download” button.

A .msi file will be downloaded.

Install
At the time you install MongoDB, a newer version may be available.
Run the .msi file. You see the installation wizard. Click on the “Next” button.
Read and accept the terms in the License Agreement and click on the “Next” button.

The setup type is “Complete” by default. Choose “Complete”.

In the Service Configuration page, leave everything as default and do not change anything. Click
on the “Next” button.
In the next page leave the “Install Mongo Compass” checked and click on the “Next” button.

Click on “Install”. When the install process is completed, click on the “Finish” button.
Run MongoDB
On your computer, go to the directory where MongoDB is installed and go to the “bin”
directory.
C:\Program Files\MongoDB\Server\4.2\bin

You can find MongoDB executable files here:


mongo.exe
mongod.exe

To run MongoDB, open the Windows command prompt and go to the “bin” directory of
MongoDB.
Before you run MongoDB, first create the following directory if it does not exist.
C:\data\db\

Now, execute “mongod” in your command prompt. MongoDB should be running with no
errors.

Open a new command prompt. Go to the “bin” directory of MongoDB.


C:\Program Files\MongoDB\Server\4.2\bin
Execute “mongo” in your command prompt which opens the Mongo Client shell.
Execute the following command to see all existing databases in your MongoDB:
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB

A new MongoDB database is created when you insert data to the database.
To create a new database, execute the following command:
> use library
The “use” command, makes a database your current one. However, since we have not inserted
data into the “library” database, you will not see this database as an existing one. We run the
“use library” command to tell MongoDB that our current database will be the “library”
database.
Now, insert data (a document) into the “library” database.

> db.book.insertOne({"title": "Blue Sky"})


{
"acknowledged" : true,
"insertedId" : ObjectId("5eb42fa3062af495b2bfba9c")
}

“book” is a collection that stores documents. We later learn about collections and documents.
We stored data for a book in our “library” database.
Now, if you show the list of databases, you will see the new database “library” in your list:

> show dbs


admin 0.000GB
config 0.000GB
library 0.000GB
local 0.000GB

You might also like