How To Install MongoDB On Windows Operating System?
The MongoDB document-based database is open-source, cross-platform, and scalable. MongoDB Inc. developed it as a NoSQL database.
The name MongoDB comes from the word “humongous,” which means enormous.
The MongoDB database can store a large amount of data and perform quickly at the same time.
Step 1: Install MongoDB by downloading the MSI package
You can download MongoDB‘s current version here. Select MSI as the package you desire to download.
Step 2: Install MongoDB
Read our article to learn how to install mongodb on linux.
Read our article to learn how to install mongodb on Mac.
- You must be logged in as a user with admin privileges. Once you have downloaded the .msi package, navigate to the downloads folder and double click it. You will be prompted to launch the installation wizard.
- Start the installation by clicking Next.
- Click Next after accepting the licence agreement.
- The Complete setup option should be selected.
- Note the data directory and select “Run service as Network Service user” later on.
- You won’t need Mongo Compass, so deselect it and then click Next.
- Start the installation by clicking Install.
- It will only take a few minutes to complete the setup
- Once the installation is complete, click Finish.
Step 3: Organize our databases in data folders
The next step will be to set up MongoDB on the local system after the installation is complete.
- Create a new folder called data on the C Drive (c:) using Windows Explorer on your computer.
- Create a folder called db inside the data folder you just created in previous step.
Step 4: Setup Alias Shortcuts
- Copy the bin path to the location where MongoDB is installed on your system: C:\Program Files\MongoDB\Server\6.0\bin
- Click on System Properties > Environment Variables > System Variables > Path and Click Edit button to create an environment variable.
- Click New and paste the copied environment system link into Edit Environment Variable and click Ok.
- The MongoDB server, mongod, will be run after the environment variable has been set. Open the command prompt and run the following command:
mongod
Step 5: Run mongo Shell
We will now connect our server (mongod) to the mongo shell.
- Keep the mongod window open and open a new command prompt window and type mongo. Mongod will now be successfully connected to our mongo shell.
- Don’t close the mongod window – closing this window will stop your server from functioning and it will be unable to connect with the mongo shell.
- The mongo shell is now ready for you to write queries.
- In your shell, you can now create databases, collections, and documents. Here is an example of how to create a new database.
- Use Database_name creates a new database in the system if it does not exist, or uses an existing database:
use mynewmongodb
You now have a database named mynewmongodb ready to use.
- Db.Collection_name creates a new collection in mynewmongodb, and insertOne() inserts the document into the firm collection:
db.firm.insertOne({Tesla:999})