Choorai
Lv.2

NoSQL Database

Store data flexibly without pre-defining a schema. The most common form is the document format, similar to JSON.

What is this?

Store data in JSON-like format without a schema. Flexible structure.

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 popular

The leading document-based NoSQL. Easy to get started with the cloud-managed Atlas service. Provides powerful queries and aggregation pipelines.

Firestore

Built into Firebase

NoSQL DB included in Google Firebase. With real-time listeners, data changes are automatically reflected on the client.

DynamoDB

AWS

AWS 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
# 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
# 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 doc

Hono + mongodb (TypeScript)

src/db.ts
// 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
// 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.

Last updated: February 22, 2026 · Version: v0.0.1

Send Feedback

Opens a new issue page with your message.

Open GitHub Issue