DEV Community

Alex Spinov
Alex Spinov

Posted on

MongoDB Atlas Has a Free API — Here's How to Build a Full Backend in 10 Minutes

A solo developer I know was paying $50/month for a PostgreSQL instance that held 200MB of data. He switched to MongoDB Atlas free tier — same data, same speed, $0/month. That was 2 years ago and he's still on the free tier.

What Atlas Free Tier Includes

MongoDB Atlas M0 (free forever):

  • 512 MB storage — enough for most side projects and MVPs
  • Shared RAM — adequate for moderate traffic
  • MongoDB 7.0+ with all features
  • Atlas Data API — REST API for your database (no driver needed!)
  • Atlas Search — full-text search built in
  • Charts — visualize data without code
  • 3 replica set nodes — automatic failover

Quick Start: Atlas Data API

The Data API lets you query MongoDB via REST — no driver, no connection strings:

# Enable Data API in Atlas dashboard > App Services > Data API

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": { "status": "active" },
    "limit": 10
  }'
Enter fullscreen mode Exit fullscreen mode

CRUD with Data API

const ATLAS_API = 'https://data.mongodb-api.com/app/YOUR_APP_ID/endpoint/data/v1';
const API_KEY = process.env.ATLAS_API_KEY;

async function atlasRequest(action, body) {
  const res = await fetch(`${ATLAS_API}/action/${action}`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json', 'api-key': API_KEY },
    body: JSON.stringify({ dataSource: 'Cluster0', database: 'myapp', ...body })
  });
  return res.json();
}

// Insert
await atlasRequest('insertOne', {
  collection: 'products',
  document: { name: 'Widget', price: 29.99, tags: ['new', 'sale'] }
});

// Find with filter
const { documents } = await atlasRequest('find', {
  collection: 'products',
  filter: { price: { $lt: 50 } },
  sort: { price: 1 },
  limit: 20
});

// Update
await atlasRequest('updateOne', {
  collection: 'products',
  filter: { name: 'Widget' },
  update: { $set: { price: 24.99 }, $push: { tags: 'discounted' } }
});

// Aggregate
const { documents: stats } = await atlasRequest('aggregate', {
  collection: 'orders',
  pipeline: [
    { $match: { status: 'completed' } },
    { $group: { _id: '$product', total: { $sum: '$amount' }, count: { $sum: 1 } } },
    { $sort: { total: -1 } }
  ]
});
Enter fullscreen mode Exit fullscreen mode

Node.js Driver (Traditional)

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

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

async function createUser(userData) {
  return db.collection('users').insertOne({
    ...userData,
    createdAt: new Date(),
    status: 'active'
  });
}

async function searchProducts(query) {
  return db.collection('products').aggregate([
    { $search: { text: { query, path: ['name', 'description'] } } },
    { $limit: 10 },
    { $project: { name: 1, price: 1, score: { $meta: 'searchScore' } } }
  ]).toArray();
}
Enter fullscreen mode Exit fullscreen mode

Atlas Search (Full-Text Search)

// Create search index in Atlas UI, then query:
const results = await db.collection('articles').aggregate([
  {
    $search: {
      compound: {
        must: [{ text: { query: 'javascript', path: 'tags' } }],
        should: [{ text: { query: 'tutorial beginner', path: 'title', score: { boost: { value: 2 } } } }]
      }
    }
  },
  { $limit: 10 },
  { $project: { title: 1, summary: 1, score: { $meta: 'searchScore' } } }
]).toArray();
Enter fullscreen mode Exit fullscreen mode

Perfect For

  • MVPs and prototypes — flexible schema, no migrations
  • Content management — nested documents, rich queries
  • E-commerce — product catalogs with faceted search
  • Real-time apps — change streams for live updates
  • Mobile backends — Atlas Device Sync

Need to scrape data into MongoDB? Check out my web scraping actors on Apify — collect data from any website and export to JSON/CSV.

Need a custom data pipeline? Email me at spinov001@gmail.com — I build scraping-to-database solutions.

Top comments (0)