Type something to search...
Getting Started with MongoDB Atlas: Setting Up Your First Free Cluster

Getting Started with MongoDB Atlas: Setting Up Your First Free Cluster

Running your own database means thinking about disks, backups, upgrades, replica sets, and security patches before you've written a single query. For a side project, a prototype, or a learning environment, that's a lot of overhead for very little payoff.

MongoDB Atlas is MongoDB's managed cloud service. It runs your database on AWS, Google Cloud, or Azure and handles the operational work for you. Even better for getting started, Atlas offers a permanently free tier, the M0 cluster, which gives you a real three-node replica set with enough storage to build and test a genuine application.

This guide covers how Atlas is organized, creating an M0 cluster step by step, configuring database users and network access, connecting from mongosh, Node.js, and Python, loading sample data, doing the same thing from the Atlas CLI, and the free tier limits you should know before you rely on it.

How Atlas Is Organized

Atlas has a small hierarchy that's worth understanding before you click anything:

  • Organization: the top level, usually your company or your personal account. Billing and org-wide users live here.
  • Project: a group of clusters that share network settings, database users, and alerts. A common pattern is one project per environment (myapp-dev, myapp-prod).
  • Cluster: the actual database deployment. Each cluster is a replica set (or a sharded cluster on larger tiers).

This matters because database users and IP access lists are defined at the project level, not per cluster. A user you create in the dev project can connect to every cluster in that project, and none in prod. Separate projects are the simplest way to keep environments isolated.

Choosing a Cluster Tier

Atlas offers three broad kinds of clusters:

TierWhat it isGood for
M0 (Free)Shared infrastructure, 512 MB of storage, no chargeLearning, prototypes, demos
FlexShared infrastructure, usage-based pricing with a monthly capSmall apps, low-traffic production
Dedicated (M10+)Your own VMs, configurable storage, backups, and full feature setProduction workloads

Flex clusters replaced the older M2/M5 shared tiers and Serverless instances in 2025, so if an older tutorial mentions those, Flex is the modern equivalent. Pricing and exact limits change over time, so check the Atlas pricing page before you plan a budget. For this guide, we'll use M0, which costs nothing and doesn't require a payment method.

Step 1: Create an Account and Project

  1. Sign up at the MongoDB Atlas site with an email address or a Google or GitHub account.
  2. Atlas creates a default organization and project for you. You can rename the project to something meaningful from Project Settings, or create a new one from the project dropdown at the top left.

If you plan to use Atlas for more than one app, create a dedicated project now. Moving clusters between projects later isn't possible without migrating data.

Step 2: Deploy an M0 Cluster

From your project's overview page, click Create (sometimes labeled Build a Cluster). You'll see the deployment options:

  1. Choose Free (M0).
  2. Give the cluster a name. You can't rename a cluster later, so pick something like dev-cluster rather than the default Cluster0 if you care about tidy connection strings.
  3. Choose a cloud provider and region. Pick the region closest to where your application (or you) will run. Latency between your app and the database adds up on every query.
  4. Leave the option to preload sample data checked if you want example datasets to explore right away.
  5. Click Create Deployment.

Provisioning takes a minute or two. While it runs, Atlas opens a security quickstart dialog, which is the next step.

Step 3: Create a Database User

Atlas never allows unauthenticated connections. You need at least one database user, which is separate from your Atlas login. Your Atlas account manages the project; a database user is what your application uses to connect.

In the quickstart dialog (or later under Security > Database Access):

  1. Choose Username and Password authentication.
  2. Enter a username, like app_dev.
  3. Click Autogenerate Secure Password and copy it somewhere safe, such as a password manager or your local .env file.
  4. Under privileges, the default Read and write to any database is fine for a dev cluster. For production, create users scoped to specific databases.

A practical tip: autogenerated passwords avoid special characters that need URL encoding. If you choose your own password with characters like @, :, /, or %, you must percent-encode them in the connection string, or the driver will misread the URI.

Step 4: Configure Network Access

Atlas blocks all network traffic by default. You have to add the IP addresses that are allowed to connect in the IP Access List (under Security > Network Access).

  • Click Add My Current IP Address to allow your own machine.
  • For a deployed app, add the outbound IP address of your server or hosting platform.

You'll often see advice to add 0.0.0.0/0 (allow access from anywhere). That does work, and it's sometimes the only practical option for platforms with changing IP addresses, but it means your password is the only thing protecting the cluster. If you use it, make sure passwords are long and random, and prefer adding it as a temporary entry (Atlas lets you set an expiry) while you experiment.

Dedicated clusters support private networking options like VPC peering and private endpoints, which avoid the public internet entirely. Those aren't available on M0.

Step 5: Get Your Connection String

When the cluster is ready, click Connect on the cluster card. Atlas shows several options (Drivers, Compass, Shell, and others). Each one gives you a connection string that looks like this:

mongodb+srv://app_dev:<db_password>@dev-cluster.ab1cd.mongodb.net/?retryWrites=true&w=majority&appName=dev-cluster

A few pieces are worth understanding:

  • mongodb+srv:// tells the driver to look up the cluster's hosts through a DNS SRV record, so you don't need to list all three replica set members yourself.
  • retryWrites=true enables automatic retry of certain write operations after transient network errors or failovers.
  • w=majority means writes are acknowledged only after a majority of replica set members have them, which protects against data loss during failover.
  • appName labels your connections, which makes them easy to identify in logs and monitoring.

Replace <db_password> with the real password. Don't commit this string to source control. Put it in an environment variable instead:

# .env (and add .env to .gitignore)
MONGODB_URI="mongodb+srv://app_dev:s3cr3tGeneratedPass@dev-cluster.ab1cd.mongodb.net/?retryWrites=true&w=majority&appName=dev-cluster"

Step 6: Connect and Run Your First Query

From mongosh

If you have mongosh installed, connect directly:

mongosh "mongodb+srv://dev-cluster.ab1cd.mongodb.net/" --username app_dev

mongosh prompts for the password. If you loaded the sample data, try a query against the movies dataset:

use sample_mflix
db.movies.find(
  { year: 1994, "imdb.rating": { $gte: 8.5 } },
  { title: 1, "imdb.rating": 1, _id: 0 }
).sort({ "imdb.rating": -1 })
[
  { title: 'The Shawshank Redemption', imdb: { rating: 9.3 } },
  { title: 'Pulp Fiction', imdb: { rating: 8.9 } },
  ...
]

(Exact results depend on the version of the sample dataset.) For a full tour of the shell, see Mastering mongosh: Essential MongoDB Shell Commands.

From Node.js

Install the official driver:

npm install mongodb

Then connect using the URI from your environment:

// index.mjs
import { MongoClient } from "mongodb";

const client = new MongoClient(process.env.MONGODB_URI);

try {
  await client.connect();
  const db = client.db("sample_mflix");

  const result = await db.command({ ping: 1 });
  console.log("Ping:", result);

  const movie = await db
    .collection("movies")
    .findOne({ title: "The Matrix" }, { projection: { title: 1, year: 1 } });
  console.log(movie);
} finally {
  await client.close();
}
node --env-file=.env index.mjs
Ping: { ok: 1 }
{ _id: new ObjectId('573a139bf29313caabcf3d23'), title: 'The Matrix', year: 1999 }

The --env-file flag is built into recent Node.js versions, so you don't need the dotenv package for a quick test. In a real application, create one MongoClient when the app starts and reuse it everywhere; the client manages a connection pool internally.

From Python

With PyMongo:

pip install "pymongo[srv]"
import os
from pymongo import MongoClient

client = MongoClient(os.environ["MONGODB_URI"])

print(client.admin.command("ping"))

db = client["sample_mflix"]
for movie in db.movies.find({"genres": "Animation"}, {"title": 1, "_id": 0}).limit(3):
    print(movie)

The [srv] extra pulls in dnspython, which older PyMongo versions needed to resolve mongodb+srv:// URIs. Recent versions include it by default, but the extra is harmless.

Exploring Data in the Atlas UI

Back in the Atlas web interface, click Browse Collections (the Data Explorer) on your cluster. You can:

  • Browse databases and collections, and page through documents.
  • Filter with a query document, like { "year": { "$gt": 2010 } }.
  • Insert, edit, and delete documents.
  • Build and run aggregation pipelines stage by stage.
  • Create and view indexes.

The sample datasets are a great playground: sample_mflix (movies and comments), sample_airbnb (listings with geospatial data), sample_supplies (sales), and several others. If you skipped them during setup, use the cluster's ... menu and choose Load Sample Dataset.

For a more powerful desktop experience with the same capabilities, MongoDB Compass connects to Atlas with the same connection string. See How to Use MongoDB Compass to Explore and Manage Your Data.

Doing It All from the Atlas CLI

If you prefer the terminal or want reproducible setups, the Atlas CLI can do everything above. Install it with Homebrew (brew install mongodb-atlas-cli), winget, or a Linux package, then:

# Authenticate in the browser
atlas auth login

# Create a free cluster
atlas clusters create dev-cluster --provider AWS --region US_EAST_1 --tier M0

# Create a database user
atlas dbusers create readWriteAnyDatabase --username app_dev --password 'use-a-long-random-password'

# Allow your current IP
atlas accessLists create --currentIp

# Print the connection string once the cluster is ready
atlas clusters connectionStrings describe dev-cluster

There's also atlas setup, an interactive command that walks you through account creation, cluster creation, user and access list configuration, and sample data in one go. Flag names occasionally change between CLI versions, so run atlas clusters create --help if a command is rejected.

Free Tier Limits to Know

M0 is genuinely useful, but it's shared infrastructure with real constraints. At the time of writing, the key limits are:

  • 512 MB of storage. Indexes count toward it. The sample datasets use a good chunk of it, so drop the ones you don't need.
  • One M0 cluster per project. Create additional projects if you need more free clusters.
  • Shared CPU and RAM, with throughput limits on operations and a cap on concurrent connections.
  • No automated backups. If the data matters, export it yourself with mongodump.
  • Feature restrictions. Some features (certain server parameters, advanced networking, some monitoring views) are only available on dedicated tiers.
  • Idle pausing. Atlas may pause free clusters that have had no connections for an extended period. You can resume them from the UI.

The exact numbers evolve, so check the Atlas documentation for the current M0 limits. When you outgrow M0, you can upgrade the cluster in place to Flex or a dedicated tier from the cluster's Edit Configuration page. Your connection string stays the same.

Common Mistakes

Confusing your Atlas login with a database user. Your email and password log you into the Atlas website. Your application needs a database user created under Database Access. Authentication errors like bad auth : authentication failed almost always mean the wrong user, the wrong password, or an unencoded special character.

Forgetting the IP access list. A connection that hangs and then times out (rather than failing with an auth error) usually means your IP isn't allowed. Home and office IPs change, so re-add your current IP when things suddenly stop working.

Hardcoding the connection string. It contains credentials. Keep it in environment variables or a secrets manager, and rotate the password if it ever lands in a public repository.

Creating a new client per request. Opening a fresh MongoClient for every HTTP request exhausts connections quickly, especially on the M0 connection cap. Create the client once and reuse it.

Treating M0 as production. No backups and shared resources make it a poor home for data you can't afford to lose. Use Flex or a dedicated tier for anything real.

Conclusion

Atlas removes the operational work of running MongoDB, and the M0 tier makes it free to start. The setup is always the same sequence: create a project, deploy a cluster, add a database user, allow your IP address, and copy the mongodb+srv:// connection string into an environment variable. From there, mongosh, Compass, and every official driver connect the same way.

As a next step, load the sample datasets into your new cluster and write three queries against sample_mflix from the language you use most. Once that works, you have everything you need to point a real project at Atlas.

Tags :
Share :

Related Posts

A Complete Guide to MongoDB Query Operators

A Complete Guide to MongoDB Query Operators

Your first MongoDB queries are usually simple equality filters: find the user with this email, find orders with this status. That covers a surprising

Continue Reading
Async MongoDB in Python with Motor and FastAPI

Async MongoDB in Python with Motor and FastAPI

FastAPI runs your endpoints on an event loop. That's what lets a single worker juggle hundreds of concurrent requests: while one request waits on the

Continue Reading
Atlas Online Archive: Tiering Cold Data to Cut Costs

Atlas Online Archive: Tiering Cold Data to Cut Costs

Look at almost any production database and you'll find the same shape. A small slice of recent data gets nearly all the reads and writes: this week's

Continue Reading