Lesson 15 of 18

MongoDB Atlas (Cloud)

What is MongoDB Atlas?

MongoDB Atlas is a fully managed cloud database service. It handles deployment, scaling, backups, and security so you can focus on building your application.

  • Free tier with 512MB storage — perfect for learning and small projects
  • Deploy on AWS, Google Cloud, or Azure
  • Automatic backups and point-in-time recovery
  • Built-in monitoring and alerts
  • Network security with IP whitelisting and VPC peering
  • Global clusters for worldwide data distribution

Connecting to Atlas

After creating a cluster on Atlas, get your connection string and use it in your application.

Example
// Connection string from Atlas dashboard
const uri = 'mongodb+srv://username:password@cluster0.xxxxx.mongodb.net/mydb?retryWrites=true&w=majority';

// With Mongoose
const mongoose = require('mongoose');
mongoose.connect(uri)
  .then(() => console.log('Connected to Atlas!'))
  .catch(err => console.error(err));

// With native driver
const { MongoClient } = require('mongodb');
const client = new MongoClient(uri);
await client.connect();
const db = client.db('mydb');