DateBase
Mongodb

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.

4. MongoDB Atlas (Cloud)

MongoDB Atlas is a fully managed cloud database service.

Conclusion

MongoDB is now set up and ready to use. Use MongoDB Compass for GUI-based management or Atlas for cloud-based deployment.


🧙 AI Wizard - Instant Page Insights

Click the button below to analyze this page.
Get an AI-generated summary and key insights in seconds.
Powered by Perplexity AI!