MongoDB Atlas

Introduction

MongoDB Atlas is MongoDB’s managed cloud service—replica sets, backups, monitoring, and TLS without operating your own mongod servers. The free M0 tier is enough for learning and small prototypes. This chapter walks through cluster creation, network access, database users, connection strings, and migrating from local Docker to Atlas.

Prerequisites

Atlas vs Self-Hosted

AtlasSelf-hosted
Ops burdenLowYou patch, backup, monitor
Free tierM0 sharedDocker local free
TLSOn by defaultYou configure
BackupsAutomated (paid tiers)mongodump scripts
Best forProduction start, teams without DBAsFull control, air-gapped

Step 1: Create an Account and Project

  1. Go to mongodb.com/atlas
  2. Sign up (Google/GitHub or email)
  3. Create an Organization and Project (e.g. hello-code-learn)

Step 2: Build a Free Cluster (M0)

  1. CreateSharedM0 FREE
  2. Cloud provider: AWS / GCP / Azure — pick region near you
  3. Cluster name: Cluster0 (default OK)
  4. MongoDB version: 7.0 (or latest stable)
  5. Create cluster (provisioning takes a few minutes)

M0 limits (approximate, check Atlas docs):

  • Shared CPU/RAM
  • 512 MB storage
  • No dedicated VPC peering on free tier
  • Suitable for tutorials—not production load

Step 3: Network Access

Atlas blocks all IPs by default.

  1. Network AccessAdd IP Address
  2. Dev: Add Current IP Address
  3. CI/CD: add runner IP or use 0.0.0.0/0 only for short-lived dev (insecure—remove after)

Warning

Do Not Use 0.0.0.0/0 in Production

Open IP list exposes database to the internet if credentials leak. Use VPC peering or private endpoints on paid tiers.

Step 4: Database User

  1. Database AccessAdd New Database User
  2. Authentication: Password
  3. Username: app_user (example)
  4. Strong random password—store in password manager
  5. Privileges: Read and write to any database for learning, or Specific Privileges (readWrite on hello_demo) for production style

Atlas uses SCRAM-SHA-256 by default.

Step 5: Connect With mongosh

  1. DatabaseConnectDrivers or mongosh
  2. Copy connection string:
text
mongodb+srv://app_user:<password>@cluster0.xxxxx.mongodb.net/?retryWrites=true&w=majority

Replace <password> with URL-encoded password.

bash
mongosh "mongodb+srv://app_user:YOUR_PASSWORD@cluster0.xxxxx.mongodb.net/hello_demo"

Verify:

javascript
db.runCommand({ ping: 1 })
db.posts.insertOne({ title: "From Atlas", slug: "from-atlas", published: true })

Connection String Options

ParameterPurpose
retryWrites=trueRetry transient network errors
w=majorityDurable write acknowledgment
appName=HelloCodeIdentify app in Atlas logs

PyMongo / FastAPI use the same URI in MONGODB_URI env var — PyMongo.

Atlas UI Features (Overview)

FeatureUse
CollectionsBrowse, insert, filter documents
IndexesCreate/drop; Performance Advisor suggests indexes
MetricsConnections, ops, disk
AlertsEmail on high CPU, replication lag
BackupContinuous backup on M10+
Atlas SearchFull-text search index (paid)
ChartsBI dashboards from collections

Migrate Local Data to Atlas

Option A: mongodump / mongorestore

bash
mongodump --uri="mongodb://127.0.0.1:27017" --db=hello_demo --out=./dump
 
mongorestore --uri="mongodb+srv://app_user:PASS@cluster0.xxxxx.mongodb.net" \
  --db=hello_demo \
  ./dump/hello_demo

Option B: mongoexport / mongoimport

For single collections or JSON fixtures — Insert and Import Export.

Option C: Atlas Live Migration

Paid migration service from self-hosted or other cloud—use for large production cutovers.

Environment Variables in Apps

.env (never commit):

env
MONGODB_URI=mongodb+srv://app_user:secret@cluster0.xxxxx.mongodb.net/hello_demo?retryWrites=true&w=majority

Load in Python:

python
import os
uri = os.environ["MONGODB_URI"]

See Git gitignore for .env.

Atlas vs Local Docker Workflow

TaskLocal DockerAtlas
Quick CRUD learningFast, offlineNeeds internet
Team shared DBPort forward / tunnelInvite to project
ProductionYou operateAtlas patches & monitors
CostFree (your hardware)M0 free; scales to paid

Many teams develop locally, deploy staging/prod to Atlas.

Security Checklist on Atlas

  • IP access list restricted
  • App user least privilege (not atlasAdmin)
  • Strong password or use IAM auth (advanced)
  • MONGODB_URI in secrets manager in production
  • Enable backup on paid tier before launch

Details — MongoDB Security.

Post-Chapter Checklist

  • M0 cluster created and reachable
  • Database user and IP whitelist configured
  • mongosh connected with mongodb+srv://
  • Test document inserted in hello_demo
  • You know mongodump/mongorestore migration path

FAQ

M0 sleep or pause?

Free tier may throttle; first request after idle can be slow.

Wrong password / auth failed?

URL-encode special characters in password; check username and authSource.

srv vs standard connection?

mongodb+srv:// resolves Atlas seed list; use standard mongodb://host:27017 if DNS SRV blocked.

Multiple environments?

Separate Atlas projects or clusters: dev, staging, prod.

Atlas vs AWS DocumentDB?

DocumentDB is AWS-managed, MongoDB-compatible API—not full MongoDB feature parity; prefer Atlas for latest features.

Delete cluster to avoid charges?

M0 is free; delete project/cluster when done experimenting to avoid accidental upgrades.