MongoDB Setup Guide
1. Installing MongoDB
For Ubuntu/Debian:
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
sudo apt update && sudo apt install -y mongodb-org
Start & Enable MongoDB:
sudo systemctl start mongod
sudo systemctl enable mongod
sudo systemctl status mongod
2. Basic MongoDB Commands
mongo # Open MongoDB shell
show dbs # List all databases
use mydatabase # Switch to a database
show collections # Show collections in the database
db.users.insertOne({name: "John", age: 30}) # Insert a document
db.users.find() # Retrieve all documents from 'users' collection
3. MongoDB Compass (GUI)
MongoDB Compass is a GUI tool to visualize and interact with MongoDB data.
- Download from: https://www.mongodb.com/try/download/compass (opens in a new tab)
- Install and connect to your MongoDB instance easily.
4. MongoDB Atlas (Cloud)
MongoDB Atlas is a fully managed cloud database service.
- Sign up at: https://www.mongodb.com/atlas (opens in a new tab)
- Create a free cluster and connect using MongoDB Compass or CLI.
Conclusion
MongoDB is now set up and ready to use. Use MongoDB Compass for GUI-based management or Atlas for cloud-based deployment.