Lab Manual - Mongodb
Lab Manual - Mongodb
Lab Manual - Mongodb
Objectives
Prerequisites
Installation Steps
For Windows:
For macOS:
bash
brew tap mongodb/brew
2. Otherwise, you can download the .tgz file and follow the instructions to extract and set it up
manually.
For Linux (Ubuntu example):
Open the terminal.
Run the following commands:
MongoDB stores its data in /data/db by default. Create this directory and set permissions:
# For macOS/Linux
sudo mkdir -p /data/db
sudo chown `id -u` /data/db
For Windows, you may skip this step as MongoDB will create the necessary directories
automatically.
Mongosh
1. You should see the MongoDB shell prompt (>) if it starts correctly.
Once in the MongoDB shell, you can try the following commands:
use myTestDB
2. Create a new collection and insert a document:
db.myCollection.insertOne({ name: "Alice", age: 25 })
3. View documents:
db.myCollection.find().pretty()
Conclusion
You have successfully installed MongoDB and performed basic operations! Explore more
features and commands as you continue your MongoDB journey.
Troubleshooting Tips