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
- Installation and mongosh — local MongoDB experience
- Replica Sets and Sharding Intro — Atlas runs replica sets for you
- Email account and browser; mongosh installed locally
Atlas vs Self-Hosted
| Atlas | Self-hosted | |
|---|---|---|
| Ops burden | Low | You patch, backup, monitor |
| Free tier | M0 shared | Docker local free |
| TLS | On by default | You configure |
| Backups | Automated (paid tiers) | mongodump scripts |
| Best for | Production start, teams without DBAs | Full control, air-gapped |
Step 1: Create an Account and Project
- Go to mongodb.com/atlas
- Sign up (Google/GitHub or email)
- Create an Organization and Project (e.g.
hello-code-learn)
Step 2: Build a Free Cluster (M0)
- Create → Shared → M0 FREE
- Cloud provider: AWS / GCP / Azure — pick region near you
- Cluster name:
Cluster0(default OK) - MongoDB version: 7.0 (or latest stable)
- 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.
- Network Access → Add IP Address
- Dev: Add Current IP Address
- 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
- Database Access → Add New Database User
- Authentication: Password
- Username:
app_user(example) - Strong random password—store in password manager
- Privileges: Read and write to any database for learning, or Specific Privileges (
readWriteonhello_demo) for production style
Atlas uses SCRAM-SHA-256 by default.
Step 5: Connect With mongosh
- Database → Connect → Drivers or mongosh
- Copy connection string:
mongodb+srv://app_user:<password>@cluster0.xxxxx.mongodb.net/?retryWrites=true&w=majorityReplace <password> with URL-encoded password.
mongosh "mongodb+srv://app_user:YOUR_PASSWORD@cluster0.xxxxx.mongodb.net/hello_demo"Verify:
db.runCommand({ ping: 1 })
db.posts.insertOne({ title: "From Atlas", slug: "from-atlas", published: true })Connection String Options
| Parameter | Purpose |
|---|---|
retryWrites=true | Retry transient network errors |
w=majority | Durable write acknowledgment |
appName=HelloCode | Identify app in Atlas logs |
PyMongo / FastAPI use the same URI in MONGODB_URI env var — PyMongo.
Atlas UI Features (Overview)
| Feature | Use |
|---|---|
| Collections | Browse, insert, filter documents |
| Indexes | Create/drop; Performance Advisor suggests indexes |
| Metrics | Connections, ops, disk |
| Alerts | Email on high CPU, replication lag |
| Backup | Continuous backup on M10+ |
| Atlas Search | Full-text search index (paid) |
| Charts | BI dashboards from collections |
Migrate Local Data to Atlas
Option A: mongodump / mongorestore
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_demoOption 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):
MONGODB_URI=mongodb+srv://app_user:secret@cluster0.xxxxx.mongodb.net/hello_demo?retryWrites=true&w=majorityLoad in Python:
import os
uri = os.environ["MONGODB_URI"]See Git gitignore for .env.
Atlas vs Local Docker Workflow
| Task | Local Docker | Atlas |
|---|---|---|
| Quick CRUD learning | Fast, offline | Needs internet |
| Team shared DB | Port forward / tunnel | Invite to project |
| Production | You operate | Atlas patches & monitors |
| Cost | Free (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_URIin 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
-
mongoshconnected withmongodb+srv:// - Test document inserted in
hello_demo - You know
mongodump/mongorestoremigration 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.