1When do I need this?
- Data structure changes frequently (prototyping, MVP)
- Nested data needs to be stored as a whole (blog posts + comments)
- Horizontal scaling is needed (handling massive traffic)
- Real-time synchronization is required (Firestore + mobile apps)
2Key Services
MongoDB Atlas
Most popularThe leading document-based NoSQL. Easy to get started with the cloud-managed Atlas service. Provides powerful queries and aggregation pipelines.
Firestore
Built into FirebaseNoSQL DB included in Google Firebase. With real-time listeners, data changes are automatically reflected on the client.
DynamoDB
AWSAWS fully managed NoSQL. Supports key-value and document models. Guarantees consistent performance at massive scale.
3Pricing
- MongoDB Atlas - Free tier: 512MB storage, shared cluster
- Firestore - 50K reads / 20K writes / 20K deletes per day free
- DynamoDB - 25GB storage, 25 read/write units per month free
4Connection Examples
FastAPI + motor (Python, MongoDB)
# app/database.py
from motor.motor_asyncio import AsyncIOMotorClient
MONGO_URL = "mongodb+srv://user:[email protected]/mydb"
client = AsyncIOMotorClient(MONGO_URL)
db = client.mydb# app/main.py
from fastapi import FastAPI
from app.database import db
from bson import ObjectId
app = FastAPI()
@app.get("/posts")
async def get_posts():
posts = []
async for post in db.posts.find().limit(20):
post["_id"] = str(post["_id"])
posts.append(post)
return posts
@app.post("/posts")
async def create_post(title: str, content: str, tags: list[str] = []):
doc = {"title": title, "content": content, "tags": tags}
result = await db.posts.insert_one(doc)
doc["_id"] = str(result.inserted_id)
return docHono + mongodb (TypeScript)
// src/db.ts
import { MongoClient } from 'mongodb';
const MONGO_URL = 'mongodb+srv://user:[email protected]/mydb';
const client = new MongoClient(MONGO_URL);
const db = client.db('mydb');
export default db;// src/index.ts
import { Hono } from 'hono';
import db from './db';
const app = new Hono();
app.get('/posts', async (c) => {
const posts = await db.collection('posts').find().limit(20).toArray();
return c.json(posts);
});
app.post('/posts', async (c) => {
const { title, content, tags } = await c.req.json();
const result = await db.collection('posts').insertOne({
title,
content,
tags: tags || [],
createdAt: new Date(),
});
return c.json({ _id: result.insertedId, title, content, tags }, 201);
});
export default app;Choosing between RDB and NoSQL
If relationships between data are complex, RDB is the better choice. If the data structure changes frequently or rapid development is a priority, NoSQL is more suitable. Using both together is also a common pattern.