MongoDB CLI
Command-line tools for MongoDB management
⚡ What is MongoDB CLI?
MongoDB CLI is a command-line interface for managing MongoDB Atlas and Cloud services. It provides powerful tools to deploy, manage, and monitor your databases directly from your terminal.
# Quick start with MongoDB CLI
atlas clusters list
MongoDB CLI Features
Atlas Management
Manage MongoDB Atlas clusters
Deployment
Deploy and configure databases
Monitoring
Track database performance
Security
Manage access and authentication
🔹 Installing MongoDB CLI
Install the MongoDB CLI tool on your system to start managing your MongoDB Atlas deployments. The installation process varies by operating system but is straightforward on all platforms.
Installation Methods:
- macOS: Use Homebrew package manager
- Windows: Download installer from MongoDB website
- Linux: Use package manager or download binary
# macOS (Homebrew)
brew install mongodb-atlas-cli
# Windows (Chocolatey)
choco install mongodb-atlas-cli
# Linux (Download and install)
curl -o atlas https://fastdl.mongodb.org/mongocli/mongodb-atlas-cli_latest_linux_x86_64.tar.gz
tar -zxvf mongodb-atlas-cli_latest_linux_x86_64.tar.gz
# Verify installation
atlas --version
Output:
atlas version: 1.12.0 git version: abc123def456 Go version: go1.20
🔹 Authentication and Setup
Before using MongoDB CLI, authenticate with your MongoDB Atlas account. You can use API keys or interactive login to establish secure connection to your cloud resources.
🔸 Login to Atlas
# Interactive login
atlas auth login
# Login with API key
atlas auth login --apiKey PUBLIC_KEY --apiSecret PRIVATE_KEY
# Check authentication status
atlas auth whoami
# Logout
atlas auth logout
🔸 Configure Default Project
# List all projects
atlas projects list
# Set default project
atlas config set project_id YOUR_PROJECT_ID
# View current configuration
atlas config list
🔹 Cluster Management
Manage your MongoDB Atlas clusters with simple commands. Create, configure, scale, and monitor your database deployments efficiently from the command line.
🔸 List and Describe Clusters
# List all clusters in project
atlas clusters list
# Describe specific cluster
atlas clusters describe myCluster
# Watch cluster status
atlas clusters watch myCluster
🔸 Create a Cluster
# Create a free tier cluster
atlas clusters create myCluster \
--provider AWS \
--region US_EAST_1 \
--tier M0
# Create a production cluster
atlas clusters create prodCluster \
--provider AWS \
--region US_EAST_1 \
--tier M10 \
--diskSizeGB 10 \
--mdbVersion 6.0
🔸 Update and Delete Clusters
# Scale cluster tier
atlas clusters update myCluster --tier M20
# Pause cluster
atlas clusters pause myCluster
# Resume cluster
atlas clusters start myCluster
# Delete cluster
atlas clusters delete myCluster --force
🔹 Database User Management
Create and manage database users with specific roles and permissions:
# Create database user
atlas dbusers create \
--username myUser \
--password myPassword123 \
--role readWriteAnyDatabase
# List all database users
atlas dbusers list
# Delete database user
atlas dbusers delete myUser
🔹 Network Access Control
Manage IP access lists to control who can connect to your clusters:
# Add IP address to access list
atlas accessLists create \
--ip 203.0.113.0 \
--comment "Office IP"
# Allow access from anywhere (not recommended for production)
atlas accessLists create --ip 0.0.0.0/0
# List all access list entries
atlas accessLists list
# Delete access list entry
atlas accessLists delete 203.0.113.0
🔹 Monitoring and Metrics
Monitor your cluster performance and view metrics:
Available Metrics:
- Connections: Active database connections
- Operations: Read and write operations per second
- Memory: Memory usage and cache statistics
- Disk: Storage utilization and IOPS
# View cluster metrics
atlas metrics processes myCluster
# View database metrics
atlas metrics databases myCluster myDatabase
# View disk metrics
atlas metrics disks myCluster
# Get process logs
atlas logs download myCluster \
--output mongodb.log