iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

MongoDB Atlas

Atlas is MongoDB-hosted Mongo with a free tier - great for learning, prototyping, and shipping side projects without running your own replica set.

MongoDB Atlas - getting started

EXAMPLE
// 1. Sign up at https://cloud.mongodb.com
//    Create a project, then a cluster (M0 is free)
//    Region: pick the one nearest your application

// 2. Add a database user
//    Database Access -> Add New Database User
//    Username: app
//    Password: long random
//    Roles: readWrite on your DB only

// 3. Network access
//    Network Access -> Add IP Address
//    Production: lock to your VPC peering or private endpoint
//    Dev: add only your current IP, not 0.0.0.0/0

// 4. Connection string (SRV)
//    mongodb+srv://app:<password>@cluster0.xxxxx.mongodb.net/myapp?retryWrites=true&w=majority

// 5. Connect from Node
import { MongoClient } from 'mongodb';

const uri = process.env.MONGODB_URI;
const client = new MongoClient(uri, {
  serverSelectionTimeoutMS: 5000,
  maxPoolSize: 20,
});

await client.connect();
const db = client.db('myapp');
const users = db.collection('users');
await users.createIndex({ email: 1 }, { unique: true });

// 6. Useful Atlas features
//    - Performance Advisor: index suggestions from real queries
//    - Atlas Search: Lucene-backed full text search
//    - Triggers: serverless reactions to changes
//    - Backup: continuous PITR on dedicated clusters
//    - Online archive: tier cold data automatically

// 7. Cost gotchas on shared (M0/M2/M5)
//    - No backups beyond snapshot
//    - Limited connections (M0 = 500)
//    - Use only for dev or tiny side projects

Why it matters

Atlas removes the operational tax of running Mongo. For real workloads enable VPC peering or PrivateLink and never expose your cluster to 0.0.0.0/0. The Performance Advisor alone pays for itself once you have real query load.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
// MongoDB Atlas — fully-managed; free tier available.
// Whitelist your IP, create a user, paste the connection string.
Try it Yourself »

Discussion

Loading…