YouTube Video
Step 1: Download MongoDB 8 Installer
Visit the MongoDB Website:
Go to the official MongoDB Community Edition download page:
https://www.mongodb.com/try/download/community.Select the Correct Version:
- Version: Choose MongoDB 8.
- Platform: Select Windows.
- Package: Choose the MSI installer for an easy setup.
Download the Installer:
Click the Download button to start downloading the installer.
Step 2: Install MongoDB 8
Run the Installer:
Locate the downloaded.msi
file (e.g.,mongodb-windows-x86_64-8.x.msi
) in your Downloads folder and double-click it.Follow the Installation Steps:
- License Agreement: Accept the terms and click Next.
- Setup Type: Choose Complete for the default installation, which includes MongoDB Server and tools.
- Service Configuration:
- Keep the default settings to run MongoDB as a Windows service.
- This allows MongoDB to start automatically on system boot.
- Data Directory: By default, MongoDB stores data in:
C:\Program Files\MongoDB\Server\8.0\data
Start Installation:
Click Install and wait for the installation to complete.Finish Setup:
Once the installation is complete, click Finish.
Step 3: Verify Automatic PATH Configuration
The MongoDB installer automatically adds the bin
directory to the system PATH. This allows you to run MongoDB commands from the terminal without additional configuration.
Open Command Prompt:
- Press
Win + R
, typecmd
, and press Enter.
- Press
Check MongoDB Server Version:
- Run the following command:
mongod --version
- You should see the version details of MongoDB Server.
- Run the following command:
Check MongoDB Shell (mongosh):
- Run:
mongosh --version
- This verifies that the MongoDB Shell is installed and accessible globally.
- Run:
If PATH Is Not Configured Automatically
In rare cases where the PATH is not configured, follow these steps:
Locate the MongoDB installation directory. The default path is:
C:\Program Files\MongoDB\Server\8.0\bin
Add MongoDB to the PATH:
- Open the Start Menu and search for Environment Variables.
- Click Edit the system environment variables.
- In the System Properties window, click Environment Variables.
- Under System variables, find Path and click Edit.
- Click New and paste the path to MongoDB’s
bin
directory (e.g.,C:\Program Files\MongoDB\Server\8.0\bin
). - Click OK to save changes.
Verify Again:
- Open a new Command Prompt and repeat the verification steps above.
Step 4: Install MongoDB Shell (mongosh)
Visit the MongoDB Shell Download Page:
Go to https://www.mongodb.com/try/download/shell.Select Platform:
- Choose Windows and download the
.msi
installer.
- Choose Windows and download the
Install mongosh:
- Run the downloaded installer and follow the setup wizard.
- By default, mongosh will be installed in:
C:\Program Files\MongoDB\mongosh
Verify Installation:
- Open a new Command Prompt and type:
mongosh --version
- You should see the version of the MongoDB Shell.
- Open a new Command Prompt and type:
Step 5: Start MongoDB Server
Start MongoDB as a Service:
- MongoDB is installed as a Windows service. To start it, open Command Prompt and run:
net start MongoDB
- If the service is already running, you’ll see a message indicating so.
- MongoDB is installed as a Windows service. To start it, open Command Prompt and run:
Verify Connection:
- Open
mongosh
by typing:mongosh
- This connects to the MongoDB server. If successful, you’ll see the MongoDB Shell prompt:
test>
- Open
Step 6: Basic Commands to Get Started with MongoDB Shell
Once you’re in the MongoDB shell (mongosh
), try these basic commands:
Show Databases:
show dbs
Create or Switch to a Database:
use mydatabase
Insert a Document:
db.mycollection.insertOne({ name: "John", age: 30 })
Find Documents:
db.mycollection.find()
Exit the Shell:
exit
Conclusion
You’ve successfully installed MongoDB 8 and MongoDB Shell (mongosh) on Windows 11. With MongoDB up and running, you’re ready to start building scalable and flexible applications. Whether you’re storing data, running queries, or managing collections, MongoDB provides powerful tools for modern development. Happy coding!
Comments
Post a Comment
Leave Comment