> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ahmadraza.in/llms.txt
> Use this file to discover all available pages before exploring further.

# MongoDB

### **MongoDB Setup Guide**

#### **1. Installing MongoDB**

**For Ubuntu/Debian:**

```bash theme={null}
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:**

```bash theme={null}
sudo systemctl start mongod
sudo systemctl enable mongod
sudo systemctl status mongod
```

#### **2. Basic MongoDB Commands**

```bash theme={null}
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](https://www.mongodb.com/try/download/compass)
* 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](https://www.mongodb.com/atlas)
* 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.
