DEV Community

Alex Spinov
Alex Spinov

Posted on

MongoDB Atlas Has a Free API — Here's How to Build Serverless Apps with Zero DevOps

Why MongoDB Atlas?

MongoDB Atlas is a fully managed cloud database. The free tier (M0) gives you 512 MB storage with shared clusters on AWS, GCP, or Azure — forever free, no credit card.

Plus, the Atlas Data API lets you query your database via REST — no drivers, no connection strings, just HTTP.

Getting Started

1. Create Free Cluster

  1. Sign up at mongodb.com/atlas
  2. Create a free M0 cluster
  3. Add your IP to Network Access
  4. Create a database user

2. Connect with Python

from pymongo import MongoClient

client = MongoClient("mongodb+srv://user:pass@cluster0.xxxxx.mongodb.net/")
db = client["myapp"]

# Insert documents
db.users.insert_many([
    {"name": "Alice", "email": "alice@example.com", "plan": "pro", "signupDate": "2024-01-15"},
    {"name": "Bob", "email": "bob@example.com", "plan": "free", "signupDate": "2024-03-20"},
    {"name": "Charlie", "email": "charlie@example.com", "plan": "pro", "signupDate": "2024-02-10"}
])

# Query with filters
pro_users = db.users.find({"plan": "pro"}).sort("signupDate", -1)
for user in pro_users:
    print(f"{user['name']}{user['plan']} since {user['signupDate']}")

# Aggregation pipeline
pipeline = [
    {"$group": {"_id": "$plan", "count": {"$sum": 1}, "users": {"$push": "$name"}}},
    {"$sort": {"count": -1}}
]
for result in db.users.aggregate(pipeline):
    print(f"{result['_id']}: {result['count']} users — {', '.join(result['users'])}")
Enter fullscreen mode Exit fullscreen mode

3. Atlas Data API (REST — No Drivers!)

Enable Data API in Atlas dashboard, then query via HTTP:

curl -X POST https://data.mongodb-api.com/app/YOUR_APP_ID/endpoint/data/v1/action/find \
  -H 'Content-Type: application/json' \
  -H 'api-key: YOUR_API_KEY' \
  -d '{
    "dataSource": "Cluster0",
    "database": "myapp",
    "collection": "users",
    "filter": {"plan": "pro"}
  }'
Enter fullscreen mode Exit fullscreen mode

Node.js Example

const { MongoClient } = require("mongodb");

const client = new MongoClient("mongodb+srv://user:pass@cluster0.xxxxx.mongodb.net/");
await client.connect();
const db = client.db("myapp");

// Full-text search (Atlas Search — free!)
await db.collection("articles").createIndex({ title: "text", body: "text" });

const results = await db.collection("articles").find(
  { $text: { $search: "serverless api" } },
  { score: { $meta: "textScore" } }
).sort({ score: { $meta: "textScore" } }).limit(10).toArray();

results.forEach(doc => console.log(`${doc.title} (score: ${doc.score})`));

// Change Streams (real-time)
const changeStream = db.collection("orders").watch();
changeStream.on("change", (change) => {
  console.log(`${change.operationType}: ${JSON.stringify(change.fullDocument)}`);
});
Enter fullscreen mode Exit fullscreen mode

Atlas Features on Free Tier

Feature Free (M0)
Storage 512 MB
Connections 500
Data API Yes
Atlas Search Yes
Charts 5 dashboards
Triggers 1M invocations
Realm Sync 1M sync operations

Use Cases

  1. Startup MVP — full backend with free tier, scale when needed
  2. Mobile apps — Realm Sync for offline-first with auto-sync
  3. Content management — flexible schema for different content types
  4. Real-time dashboards — Change Streams + Atlas Charts
  5. Search — Atlas Search with fuzzy matching, autocomplete

Need to populate your MongoDB with scraped web data? I build production-ready scrapers that output clean JSON ready for import. Check out my Apify actors or email spinov001@gmail.com for custom data pipelines.

What are you building with MongoDB Atlas? Drop a comment!

Top comments (0)