MongoDB Atlas Clusters

Managing and scaling your Atlas deployments

🌐 What are Atlas Clusters?

Atlas clusters are MongoDB deployments hosted in the cloud. They provide scalable, reliable database infrastructure with automatic replication, backups, and monitoring across multiple cloud providers and regions.


// Connect to your Atlas cluster
const uri = "mongodb+srv://cluster0.xxxxx.mongodb.net/";
const client = new MongoClient(uri);

await client.connect();
                                    

Output:

Successfully connected to cluster!

Cluster Types

🆓

M0 Free Tier

Perfect for learning and testing

// 512 MB storage
// Shared resources
// No credit card needed
📦

Shared Clusters

Low-cost shared infrastructure

// M2 and M5 tiers
// Shared CPU and RAM
// Good for small apps

Dedicated Clusters

Production-ready performance

// M10 to M700+ tiers
// Dedicated resources
// Auto-scaling available
🌍

Multi-Region

Global data distribution

// Deploy across regions
// Low latency worldwide
// Disaster recovery

🔹 Creating a Cluster

Deploy a new Atlas cluster through the web interface or using the Atlas CLI for automated deployments.

Cluster Creation Steps:

  1. Log in to MongoDB Atlas
  2. Click "Build a Cluster"
  3. Choose cloud provider (AWS, GCP, Azure)
  4. Select region closest to users
  5. Choose cluster tier (M0 for free)
  6. Name your cluster
  7. Click "Create Cluster"
# Create cluster using Atlas CLI
atlas clusters create myCluster \
  --provider AWS \
  --region US_EAST_1 \
  --tier M10 \
  --diskSizeGB 10

🔹 Cluster Configuration

Customize your cluster settings to match your application's performance, security, and availability requirements.

// Cluster configuration options
{
  "name": "production-cluster",
  "clusterType": "REPLICASET",
  "providerSettings": {
    "providerName": "AWS",
    "regionName": "US_EAST_1",
    "instanceSizeName": "M10"
  },
  "diskSizeGB": 10,
  "backupEnabled": true,
  "autoScaling": {
    "diskGBEnabled": true,
    "compute": {
      "enabled": true,
      "scaleDownEnabled": true
    }
  }
}

🔹 Scaling Your Cluster

Scale your cluster vertically by changing tier size or horizontally by adding shards as your data grows.

# Scale cluster tier using CLI
atlas clusters update myCluster --tier M20

# Enable auto-scaling
atlas clusters update myCluster \
  --enableAutoScaling \
  --autoScalingDiskGBEnabled

# Add shards for horizontal scaling
atlas clusters update myCluster --numShards 2

Scaling Options:

  • Vertical Scaling: Upgrade to larger instance (M10 → M20 → M30)
  • Horizontal Scaling: Add shards to distribute data
  • Auto-Scaling: Automatically adjust resources based on load
  • Storage Scaling: Increase disk space as needed

🔹 Cluster Regions and Providers

Choose from multiple cloud providers and regions to optimize latency and comply with data residency requirements.

// Available cloud providers
const providers = {
  AWS: ["US_EAST_1", "US_WEST_2", "EU_WEST_1", "AP_SOUTHEAST_1"],
  GCP: ["CENTRAL_US", "EASTERN_US", "WESTERN_EUROPE"],
  AZURE: ["US_EAST_2", "WEST_EUROPE", "SOUTHEAST_ASIA"]
};

// Multi-region cluster configuration
{
  "replicationSpecs": [
    {
      "regionConfigs": [
        { "regionName": "US_EAST_1", "priority": 7 },
        { "regionName": "EU_WEST_1", "priority": 6 },
        { "regionName": "AP_SOUTHEAST_1", "priority": 5 }
      ]
    }
  ]
}

🔹 Cluster Monitoring

Monitor cluster health, performance metrics, and resource utilization through the Atlas dashboard or programmatically via API.

# Get cluster metrics using CLI
atlas metrics processes describe myCluster \
  --granularity PT1M \
  --period P1DT12H

# View cluster status
atlas clusters describe myCluster

# List all clusters
atlas clusters list

Output:

NAME              STATE    VERSION
production-cluster IDLE     6.0.12
development-cluster IDLE    6.0.12

🔹 Cluster Maintenance

Atlas handles routine maintenance automatically, including updates, patches, and infrastructure management with minimal downtime.

Automatic Maintenance:

  • Version Upgrades: MongoDB version updates
  • Security Patches: OS and security updates
  • Hardware Maintenance: Infrastructure updates
  • Backup Management: Automated backup retention

Maintenance Window:

  • Configure preferred maintenance window
  • Receive notifications before maintenance
  • Rolling updates minimize downtime

🔹 Pausing and Deleting Clusters

Pause clusters to save costs during development or delete them when no longer needed.

# Pause a cluster (M10+ only)
atlas clusters pause myCluster

# Resume a paused cluster
atlas clusters start myCluster

# Delete a cluster (careful!)
atlas clusters delete myCluster --force

# Terminate cluster with backup
atlas clusters delete myCluster --keepBackups

Important Notes:

  • ⚠️ Free tier (M0) clusters cannot be paused
  • ⚠️ Paused clusters retain data but stop billing
  • ⚠️ Deleted clusters cannot be recovered unless backups exist
  • ⚠️ Always backup important data before deletion

🧠 Test Your Knowledge

What is the free tier cluster size in Atlas?