Installation and Tools
Installation and Tools
Section titled “Installation and Tools”You can run MongoDB locally or use MongoDB Atlas (cloud). Let’s look at both options.
Option 1: MongoDB Atlas (Cloud — Recommended for Beginners)
Section titled “Option 1: MongoDB Atlas (Cloud — Recommended for Beginners)”Atlas is MongoDB’s cloud database. Free tier gives you a 512MB cluster forever.
- Go to mongodb.com/atlas
- Sign up and create a free cluster
- Add your IP to the network access whitelist
- Create a database user (username + password)
- Click “Connect” → get your connection string:
mongodb+srv://username:password@cluster0.xxxxx.mongodb.net/myapp?retryWrites=true&w=majorityOption 2: Install MongoDB Locally
Section titled “Option 2: Install MongoDB Locally”Windows:
# Download from mongodb.com/try/download/community# Run installer (choose "Complete" setup)# MongoDB runs as a Windows service automaticallymacOS (Homebrew):
brew updatebrew install mongodb-community@7.0brew services start mongodb-community@7.0Linux (Ubuntu/Debian):
# Import the public keycurl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
# Add repositoryecho "deb [ signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
# Installsudo apt updatesudo apt install -y mongodb-orgsudo systemctl start mongodTools You’ll Use
Section titled “Tools You’ll Use”flowchart LR Dev[Developer] --> mongosh[MongoDB Shell<br/>mongosh] Dev --> Compass[MongoDB Compass<br/>GUI Tool] Dev --> App[Your App Code<br/>Node.js / Python]
mongosh --> DB[(MongoDB<br/>Database)] Compass --> DB App --> Driver[Database Driver<br/>mongoose / pymongo] Driver --> DB
style mongosh fill:#7c3aed,color:#fff style Compass fill:#7c3aed,color:#fff style DB fill:#3b82f6,color:#fff style Driver fill:#059669,color:#fff1. mongosh (MongoDB Shell)
Section titled “1. mongosh (MongoDB Shell)”The interactive JavaScript shell for MongoDB. This is your primary tool for querying and managing data.
# Connect to local MongoDBmongosh
# Connect to a remote servermongosh "mongodb+srv://cluster0.xxxxx.mongodb.net/myapp" --username myuser
# Common commands once connectedshow dbs # list databasesuse myapp # switch to databaseshow collections # list collectionsdb.help() # get help2. MongoDB Compass (GUI)
Section titled “2. MongoDB Compass (GUI)”A graphical tool to view, query, and manage your data visually. Great for exploring data without writing queries.
- Download from mongodb.com/products/compass
- Connect using the same connection string
- Visual query builder, schema analyzer, index management
3. Database Drivers
Section titled “3. Database Drivers”For connecting from your application code:
# Node.js / JavaScriptnpm install mongoose
# Pythonpip install pymongo
# Java# Add mongo-java-driver to your pom.xml
# Gogo get go.mongodb.org/mongo-driver/mongoQuick Start: Your First Connection
Section titled “Quick Start: Your First Connection”// Node.js with mongooseconst mongoose = require('mongoose');
async function connectDB() { try { await mongoose.connect('mongodb://localhost:27017/myapp'); console.log('✅ Connected to MongoDB'); } catch (err) { console.error('❌ Connection failed:', err.message); }}
connectDB();Connection String Format
Section titled “Connection String Format”mongodb://username:password@host:port/database?options
Examples:mongodb://localhost:27017/myapp # local, no authmongodb+srv://user:pass@cluster.mongodb.net/myapp # Atlasmongodb://localhost:27017,localhost:27018/myapp # replica setIn Simple Words
Section titled “In Simple Words”- Atlas is the easiest way to start — free tier, no installation needed
- mongosh is your command-line tool for running queries
- Compass is a GUI for visually exploring your data
- Drivers (like Mongoose) let your app code talk to MongoDB