Lesson 2 of 18

Installing MongoDB & Setup

Installing MongoDB

You can install MongoDB locally or use MongoDB Atlas (cloud). For learning, MongoDB Atlas free tier is the easiest option.

Example
# Option 1: MongoDB Atlas (Recommended for beginners)
# 1. Go to mongodb.com/atlas
# 2. Create free account
# 3. Create a free cluster
# 4. Get connection string

# Option 2: Local installation
# macOS
brew install mongodb-community
brew services start mongodb-community

# Ubuntu
sudo apt install mongodb
sudo systemctl start mongod

# Verify installation
mongosh --version

MongoDB Shell (mongosh)

mongosh is the interactive shell for MongoDB. Use it to run queries, manage databases, and explore your data.

Example
# Connect to local MongoDB
mongosh

# Connect to Atlas
mongosh "mongodb+srv://cluster.xxxxx.mongodb.net/mydb" --username admin

# Basic commands
show dbs              // List all databases
use myDatabase        // Switch/create database
show collections      // List collections
db.stats()            // Database statistics
exit                  // Quit shell