⬅ Previous Topic
MongoDB Use-cases and Features OverviewNext Topic ⮕
Installing MongoDB on Linux⬅ Previous Topic
MongoDB Use-cases and Features OverviewNext Topic ⮕
Installing MongoDB on LinuxIn this tutorial, we’ll walk through how to install MongoDB Community Edition on Windows. By the end, you’ll be able to run MongoDB locally on your system using both the shell and GUI.
Visit the official MongoDB download page:
https://www.mongodb.com/try/download/community
Select the following options:
Click Download and save the MSI file to your system.
Double-click the downloaded .msi
file to start the installation wizard. Follow these steps:
After installation, MongoDB should be available in your system path.
Open Command Prompt and run:
mongod --version
Output:
db version v7.0.0 Build Info: ...
This confirms MongoDB is installed. Now, let’s start the database server.
MongoDB needs a folder to store its data files. By default, it looks for C:\data\db
.
Run the following commands to create the required folder:
md \data\db
Make sure the folder exists or MongoDB will not start.
Now start the MongoDB server using this command:
mongod
Output:
{"t":{"$date":"..."},"s":"I",...,"msg":"Waiting for connections","attr":{"port":27017,...}}
This means MongoDB is running and waiting for client connections on port 27017.
Q: Why does MongoDB require a data directory like C:\data\db
?
A: MongoDB stores all of its database files (collections, indexes, documents) in this directory. Without it, MongoDB has nowhere to persist data.
Keep the server window open. Open another terminal window and run:
mongo
Output:
MongoDB shell version v7.0.0 connecting to: mongodb://127.0.0.1:27017/ test>
Now you're inside the MongoDB shell and can start issuing database commands.
Let’s insert a document into a new collection and read it back:
use mydb
db.users.insertOne({ name: "Alice", age: 25 })
db.users.find()
Output:
{ _id: ObjectId("..."), name: "Alice", age: 25 }
Explanation:
use mydb
switches to a new database called mydb
.insertOne()
adds a new document to the users
collection.find()
retrieves documents from the collection.If you prefer a visual interface, install MongoDB Compass during the installation wizard or from:
https://www.mongodb.com/try/download/compass
Compass allows you to:
In this tutorial, you installed MongoDB on Windows, started the database service, ran your first shell commands, and even inserted data. You’re now ready to start working with collections and documents.
In the next lesson, we’ll explore MongoDB’s structure — databases, collections, and documents — and learn how MongoDB organizes data.
⬅ Previous Topic
MongoDB Use-cases and Features OverviewNext Topic ⮕
Installing MongoDB on LinuxYou can support this website with a contribution of your choice.
When making a contribution, mention your name, and programguru.org in the message. Your name shall be displayed in the sponsors list.