MongoDBAtlas Cluster Setup

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
  1. Sign up at cloud.mongodb.com and create an organization + project.

  2. Click Create a Deployment, choose the M0 Free tier (512MB storage, shared RAM/vCPU — enough for learning and small side projects).

  3. Pick a cloud provider and region close to where your application runs, to minimize latency.

  4. Name the cluster and click Create — provisioning typically takes 1-3 minutes.

Note
An M0 cluster is free forever (one per project), but has no backups, limited connections, and cannot be paused. It is meant for learning and prototyping, not production traffic.
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.

Warning
0.0.0.0/0 means any IP address on the internet can attempt to connect (they still need valid database credentials, but it removes an entire layer of defense). Restrict this before storing anything sensitive.
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

readWrite on a specific database

Typical application connection

read on a specific database

Analytics/reporting connections

readWriteAnyDatabase

Admin tooling that spans multiple databases

dbAdmin

Index management, schema validation, stats — no data access

atlasAdmin

Full control of the Atlas project — reserve for project owners

4. Connection String Anatomy

Bash
mongodb+srv://appUser:<password>@cluster0.ab1cd.mongodb.net/shop?retryWrites=true&w=majority&authSource=admin

Part

Meaning

mongodb+srv://

DNS seed list protocol — resolves the full list of cluster nodes via a single SRV DNS record

appUser:<password>

Database user credentials created in step 3

cluster0.ab1cd.mongodb.net

Atlas-managed hostname for the cluster

/shop

Default database the driver connects to

retryWrites=true&w=majority

Recommended defaults for durability and resilience to transient failover

authSource=admin

Database the credentials are validated against — Atlas users are typically created against admin

5. Connecting from mongosh

Bash
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

JS
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')
Tip
Store the connection string in an environment variable or secrets manager, never committed to source control — Atlas connection strings contain credentials directly in the URL.
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.