Install MongoDB
Install MongoDB
Download
Go to the following link to download the MongoDB:
https://www.mongodb.com/download-center/community
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.
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
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.
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.
“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: