How to setup MongoDB on Windows: Step-by-step guide

How-to-setup-MongoDB-on-Windows-Step-by-step-guide

Introduction:

MongoDB is an open-source, NoSQL database system that stores data in a flexible JSON-like format called BSON (Binary JSON). It uses dynamic schemas, meaning that, unlike relational databases, MongoDB does not require a predefined schema before you add data to a database. You can alter the schema at any time and as often as necessary without having to set up a new database with an updated schema. It is designed to handle large volumes of data and provides high performance for both read and write operations.  Developers and organizations deal with large and evolving datasets and use MongoDB for its scalability, flexibility, and ease of use. 

Steps:

  1. Go to www.mongodb.com and navigate to the community server section.
  • Select the version of MongoDB Community Server-7.0.11
  • Select Windows system -x64.

Select .msi and click Download.

Navigate to MongoDB's community server section, select version 7.0.11 for Windows x64, select .msi, and click Download. 
Navigate to MongoDB’s community server section, select version 7.0.11 for Windows x64, select .msi, and click Download. 

2. Click Next on the MongoDB setup wizard.

Click 'Next' in the MongoDB setup wizard 
Click ‘Next’ in the MongoDB setup wizard 

3. Check the box in the end-user license agreement and click Next.

Check the end-user license agreement box and click 'Next' in MongoDB setup 
Check the end-user license agreement box and click ‘Next’ in MongoDB setup 

4. Check the box for Install MongoD as a service and click Next.

Check 'Install MongoDB as a service' and click 'Next' 
Check ‘Install MongoDB as a service’ and click ‘Next’ 

5. If you want to install MongoDB Compass, check the box. Otherwise, uncheck the box and click on Next.

MongoDB Compass: MongoDB Compass is a graphical user interface (GUI) tool provided by MongoDB to interact with MongoDB databases. It allows developers and database administrators to visually explore their data, run ad hoc queries, manage indexes, and perform various other tasks related to MongoDB databases.

Check the box to install MongoDB Compass or uncheck it, then click 'Next' 
Check the box to install MongoDB Compass or uncheck it, then click ‘Next’ 

6. Click Install to begin the installation.

Click 'Install' to start the MongoDB installation process 
Click ‘Install’ to start the MongoDB installation process 

7. Click Finish on the Installation Setup Wizard.

Click 'Finish' on the MongoDB Installation Setup Wizard 
Click ‘Finish’ on the MongoDB Installation Setup Wizard 

8. Click on Downloads, select the folder, and you can see Windows Installer.

Click 'Downloads,' select the folder, and view the MongoDB Windows Installer 
Click ‘Downloads,’ select the folder, and view the MongoDB Windows Installer 

9. Now, go to C drive, select Program files, and click on MongoDB.

Go to C drive, select 'Program Files,' and click on 'MongoDB 
Go to C drive, select ‘Program Files,’ and click on ‘MongoDB 

10. Select Server.

Select 'Server' under the MongoDB folder 
Select ‘Server’ under the MongoDB folder 

11. Select 7.0 (version).

Select MongoDB version 7.0 
Select MongoDB version 7.0 

12. Select bin.

Select the 'bin' folder in the MongoDB directory 
Select the ‘bin’ folder in the MongoDB directory 

13. Click on the drop-down arrow and select the path

        C:\Program Files\MongoDB\Server\7.0\bin

Select the path: C:\Program Files\MongoDB\Server\7.0\bin 
Select the path: C:\Program Files\MongoDB\Server\7.0\bin 

14. Search Environment Variables, you will see Edit the system environment variables (Control Panel) and select Open.

Search 'Environment Variables,' select 'Edit the system environment variables,' and click 'Open 
Search ‘Environment Variables,’ select ‘Edit the system environment variables,’ and click ‘Open 

15. Click on Environment Variables in the System Properties window.

Click 'Environment Variables' in the System Properties window 
Click ‘Environment Variables’ in the System Properties window 

16. Select the path and click OK.

Select the 'Path' variable, click 'OK,' and ensure the MongoDB path is included 
Select the ‘Path’ variable, click ‘OK,’ and ensure the MongoDB path is included 

17. Select New, copy the path, and click OK.

Select 'New,' add the MongoDB path, and click 'OK' 
Select ‘New,’ add the MongoDB path, and click ‘OK’ 

18. Now, install MongoDB Shell. MongoDB Shell is required to interact with MongoDB Server. Go to the Google search bar and type MongoDB shell; it will automatically take you to the MongoDB website.

MongoDB Shell: MongoShell, also known as the MongoDB Shell or simply Mongo, is an interactive JavaScript interface to MongoDB that allows developers and administrators to interact with MongoDB instances directly through a command-line interface (CLI). It’s a powerful tool that provides a way to perform various operations, such as querying and updating data, managing indexes, and executing administrative commands.

  • Select the latest version, 2.2.9.
  • Select the platform (x64).
  • Select the package-.msi. Click on Download.
Search 'MongoDB Shell,' select version 2.2.9 for platform x64, and download the .msi package
Search ‘MongoDB Shell,’ select version 2.2.9 for platform x64, and download the .msi package

19. Go to Downloads, open the folder, and click mongosh-2.2.9-x64.

Go to Downloads and click on 'mongosh-2.2.9-x64' 
Go to Downloads and click on ‘mongosh-2.2.9-x64’ 

20. Click Next on MongoDB Shell Setup Wizard.

Click 'Next' on the MongoDB Shell Setup Wizard 
Click ‘Next’ on the MongoDB Shell Setup Wizard 

21. Uncheck the box and click Next on MongoDB Shell Setup.

Uncheck the box and click 'Next' on the MongoDB Shell Setup 
Uncheck the box and click ‘Next’ on the MongoDB Shell Setup 

22. Click Install on MongoDB Shell setup.

Click 'Install' on the MongoDB Shell setup" 
Click ‘Install’ on the MongoDB Shell setup” 

23. Click on Finish to complete the installation.

Click 'Finish' to complete the MongoDB Shell installation 
Click ‘Finish’ to complete the MongoDB Shell installation 

24. Now, cmd prompt in the search bar, select Command Prompt and select Open to check MongoDB and Mongo shell installations.

Search 'Command Prompt,' select and open it to check MongoDB and Mongo Shell installations 
Search ‘Command Prompt,’ select and open it to check MongoDB and Mongo Shell installations 

25. Type mongod –version in the command prompt.

Command: C:\Users\Drushti 5>mongod --version
Type 'mongod --version' in the Command Prompt to check MongoDB version 
Type ‘mongod –version’ in the Command Prompt to check MongoDB version 

26. If the MongoDB installation is successful, we get a message as shown below.

It will show the version as V7.0.11.

If MongoDB is installed successfully, the Command Prompt will display a message showing version V7.0.11 
If MongoDB is installed successfully, the Command Prompt will display a message showing version V7.0.11 

27. Go to Command prompt again and type mongosh.

Command: C:\Users\Drushti 5>mongosh

If mongosh installation is successful, we get a message as shown below.

Type 'mongosh' in the Command Prompt to check successful installation 
Type ‘mongosh’ in the Command Prompt to check the successful installation 

28. We can test it by typing the command show dbs (it shows all the databases that are currently available on the MongoDB server).

Command: test> show dbs
Type 'show dbs' in MongoDB Shell to list all available databases 
Type ‘show dbs’ in MongoDB Shell to list all available databases 

29. The image below shows the successful mongosh installation and the databases that are currently available in MongoDB:

image shows successful mongosh installation and available MongoDB databases 
image shows successful mongosh installation and available MongoDB databases 

To create a new database, type use ss (ss is the name of the new database).

Command: test> use ss
Type 'use ss' in MongoDB Shell to create a new database named 'ss' 
Type ‘use ss’ in MongoDB Shell to create a new database named ‘ss’. 

 Now, it switches to the new database, which is SS.

30. To create the collection in the current database, type db.createCollection(“students”).

Command: ss> db.createCollection(“students”)
A message is displayed saying that 1 collection is created in the MongoDB.
{ok:1}
Type db.createCollection("students") in MongoDB Shell to create a collection named 'students' and see {ok:1} message confirming creation 
Type db.createCollection(“students”) in MongoDB Shell to create a collection named ‘students’ and see {ok:1} message confirming the creation 

We can work on MongoDB by giving different commands.

FAQs 

Q1. What is the concept of MongoDB? 

Answer: MongoDB is a non-relational document database that provides support for JSON-like storage. The MongoDB database has a flexible data model that enables you to store unstructured data, and it provides full indexing support, and replication with rich and intuitive APIs. 

Q2. What is MongoDB mostly used for? 

Answer: MongoDB is built on a scale-out architecture that has become popular with developers of all kinds for developing scalable applications with evolving data schemas. As a document database, MongoDB makes it easy for developers to store structured or unstructured data. It uses a JSON-like format to store documents. 

Q3. Which database is used in MongoDB? 

Answer: MongoDB is a NoSQL distributed database program. Because data doesn’t need to fit within the confines of a strict relationship, MongoDB can operate as a general data store. This database provides several advantages. In this type of database, data is stored in MongoDB and maps to a flexible schema. 

Q4. Which tool is best for MongoDB? 

Answer: Studio 3T is also the only MongoDB tool that has an SQL migration feature and is compatible with all major SQL databases. This makes it easy for teams to move from SQL to MongoDB. Unlike other GUIs, it also lets you import an entire database, preview documents, and customize table-to-JSON relationships. 

Q5. What data type is MongoDB? 

Answer: MongoDB uses JSON documents to store records. However, behind the scenes, MongoDB represents these documents in a binary-encoded format called BSON. BSON provides additional data types and ordered fields to allow for efficient support across a variety of languages. 

Enhance your technical writing with our expert services at The Scribe and easily configure MongoDB on Windows with our detailed guide. Reach out today to improve your documentation and streamline your setup for maximum efficiency. Start transforming your projects today!

Komal

Komal

Table of Contents

Read More

Scroll to Top