MongoDB Atlas Setup
Atlas is MongoDB's own fully managed cloud database service. It handles provisioning, patching, backups, and scaling for you, across AWS, Google Cloud, and Azure. This walkthrough gets you from zero to a connected free-tier cluster.
1. Create a Free M0 Cluster
Sign up at cloud.mongodb.com and create an organization + project.
Click Create a Deployment, choose the M0 Free tier (512MB storage, shared RAM/vCPU — enough for learning and small side projects).
Pick a cloud provider and region close to where your application runs, to minimize latency.
Name the cluster and click Create — provisioning typically takes 1-3 minutes.
2. Network Access — IP Allowlist
Atlas blocks all connections by default. Under Network Access, add the IP addresses allowed to connect.
Add Current IP Address — convenient for connecting from your own machine while developing.
Allow Access from Anywhere (0.0.0.0/0) — fine for quick learning/testing, but never leave this open on a cluster holding real data.
For production, add the specific static IPs of your servers, or use VPC/Network Peering or Private Endpoint so traffic never traverses the public internet.
3. Create a Database User
Under Database Access, create a user with SCRAM authentication (username/password) and a role scoped to what your application actually needs — avoid granting Atlas admin for an application connection.
Built-in Role | Use for |
|---|---|
| Typical application connection |
| Analytics/reporting connections |
| Admin tooling that spans multiple databases |
| Index management, schema validation, stats — no data access |
| Full control of the Atlas project — reserve for project owners |
4. Connection String Anatomy
mongodb+srv://appUser:<password>@cluster0.ab1cd.mongodb.net/shop?retryWrites=true&w=majority&authSource=admin
Part | Meaning |
|---|---|
| DNS seed list protocol — resolves the full list of cluster nodes via a single SRV DNS record |
| Database user credentials created in step 3 |
| Atlas-managed hostname for the cluster |
| Default database the driver connects to |
| Recommended defaults for durability and resilience to transient failover |
| Database the credentials are validated against — Atlas users are typically created against admin |
5. Connecting from mongosh
mongosh "mongodb+srv://cluster0.ab1cd.mongodb.net/shop" --username appUser
6. Connecting from Compass
Click Connect on the cluster overview page in Atlas, choose Compass, and copy the pre-filled connection string.
Paste it into Compass's "New Connection" dialog and supply the password when prompted.
Compass gives you a GUI for browsing collections, running queries/aggregations, and inspecting indexes without writing shell commands.
7. Connecting from a Driver
import { MongoClient } from 'mongodb'
const uri = process.env.MONGODB_URI // never hardcode credentials
const client = new MongoClient(uri)
await client.connect()
const db = client.db('shop')Cluster Tier Overview
Tier | Best for |
|---|---|
M0 (Free) | Learning, small prototypes — shared resources, 512MB storage cap |
M2 / M5 (Shared) | Low-traffic hobby projects needing a bit more headroom than M0 |
M10+ (Dedicated) | Production workloads — dedicated RAM/vCPU/storage, backups, VPC peering |
M30+ | Higher throughput production, more advanced features (sharding, analytics nodes) |
Serverless | Spiky/unpredictable traffic — pay per operation instead of a fixed instance |
Summary
Provision an M0 cluster to get started for free, upgrade to a dedicated (M10+) tier before production traffic.
Network Access controls which IPs can reach the cluster at all — never leave 0.0.0.0/0 open on anything holding real data.
Database Access controls what an authenticated connection can do — scope roles per application, avoid broad admin roles.
The mongodb+srv connection string encodes the whole cluster topology behind one DNS record — treat it as a secret.