NoSQL Patterns

Các mẫu tối ưu cho cơ sở dữ liệu NoSQL (MongoDB, Redis và hệ phân tán đa).

16 stars

Best use case

NoSQL Patterns is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Các mẫu tối ưu cho cơ sở dữ liệu NoSQL (MongoDB, Redis và hệ phân tán đa).

Teams using NoSQL Patterns should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/nosql-patterns/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/backend/nosql-patterns/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/nosql-patterns/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How NoSQL Patterns Compares

Feature / AgentNoSQL PatternsStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Các mẫu tối ưu cho cơ sở dữ liệu NoSQL (MongoDB, Redis và hệ phân tán đa).

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# NoSQL Patterns

Expert patterns for working with NoSQL databases (MongoDB, Redis, DynamoDB, etc.)

---

## When to Use This Skill

- MongoDB document database design
- Redis caching and data structures
- DynamoDB single-table design
- NoSQL performance optimization
- Choosing SQL vs NoSQL

---

## Content Map

### MongoDB
- **mongodb-patterns.md** - Document modeling
- Schema design patterns
- Indexing strategies
- Aggregation pipelines
- Transactions

### Redis
- **redis-patterns.md** - Caching strategies
- Data structures (String, Hash, List, Set, Sorted Set)
- Pub/Sub patterns
- Session storage
- Rate limiting

### DynamoDB
- **dynamodb-patterns.md** - Single-table design
- Partition & sort keys
- GSI/LSI strategies
- Query optimization

### Performance
- **performance.md** - Indexing best practices
- Query optimization
- Sharding strategies
- Connection pooling

---

## Quick Reference

### MongoDB Document Design
```javascript
// ✅ Good - Embedded for 1-to-few
{
  _id: ObjectId("..."),
  name: "John Doe",
  email: "john@example.com",
  addresses: [
    { street: "123 Main", city: "NYC", zip: "10001" },
    { street: "456 Oak", city: "LA", zip: "90001" }
  ]
}

// ✅ Good - Referenced for 1-to-many
{
  _id: ObjectId("..."),
  title: "Post Title",
  authorId: ObjectId("..."), // Reference to User
  comments: [ObjectId("..."), ObjectId("...")] // References
}
```

### MongoDB Aggregation
```javascript
db.orders.aggregate([
  { $match: { status: "completed" } },
  { $group: {
    _id: "$userId",
    totalSpent: { $sum: "$amount" },
    orderCount: { $sum: 1 }
  }},
  { $sort: { totalSpent: -1 } },
  { $limit: 10 }
]);
```

### Redis Caching Pattern
```javascript
async function getUser(userId) {
  // Try cache first
  const cached = await redis.get(`user:${userId}`);
  if (cached) return JSON.parse(cached);
  
  // Cache miss - fetch from DB
  const user = await db.users.findById(userId);
  
  // Store in cache (TTL: 1 hour)
  await redis.setex(`user:${userId}`, 3600, JSON.stringify(user));
  
  return user;
}
```

### Redis Data Structures
```javascript
// Counter
await redis.incr('page:views');

// Set (unique items)
await redis.sadd('users:online', userId);
await redis.sismember('users:online', userId);

// Sorted Set (leaderboard)
await redis.zadd('leaderboard', score, userId);
await redis.zrevrange('leaderboard', 0, 9); // Top 10
```

---

## Anti-Patterns

❌ **Treating NoSQL like SQL** → Embrace denormalization  
❌ **No indexing** → Critical for performance  
❌ **Deep nesting** → Limit to 2-3 levels  
❌ **Large arrays** → Use references for > 100 items  
❌ **No TTL on cache** → Memory leaks

---

## Best Practices

✅ **Embed for 1-to-few, reference for 1-to-many**  
✅ **Index frequently queried fields**  
✅ **Use aggregation pipelines for complex queries**  
✅ **Implement caching layer (Redis)**  
✅ **Set TTL on cached data**  
✅ **Monitor query performance**

---

## When to Use

**Use NoSQL when:**
- Flexible/evolving schema
- Horizontal scaling needed
- High write throughput
- Document/graph data model fits

**Use SQL when:**
- Complex joins required
- ACID transactions critical
- Structured, relational data
- Strong consistency needed

---

## Official Resources

- [MongoDB Manual](https://docs.mongodb.com/)
- [Redis Documentation](https://redis.io/documentation)
- [DynamoDB Guide](https://docs.aws.amazon.com/dynamodb/)

Related Skills

on-call-handoff-patterns

16
from diegosouzapw/awesome-omni-skill

Master on-call shift handoffs with context transfer, escalation procedures, and documentation. Use when transitioning on-call responsibilities, documenting shift summaries, or improving on-call pro...

nx-workspace-patterns

16
from diegosouzapw/awesome-omni-skill

Configure and optimize Nx monorepo workspaces. Use when setting up Nx, configuring project boundaries, optimizing build caching, or implementing affected commands.

nosql-expert

16
from diegosouzapw/awesome-omni-skill

Expert guidance for distributed NoSQL databases (Cassandra, DynamoDB). Focuses on mental models, query-first modeling, single-table design, and avoiding hot partitions in high-scale systems.

nosql-databases

16
from diegosouzapw/awesome-omni-skill

Apply NoSQL best practices for MongoDB, Convex, and document databases. Use when designing schemas, writing queries, optimizing performance, or building applications with non-relational databases. Use with database-expert for query optimization and DBA-level tuning (20+ years experience).

nodejs-backend-patterns

16
from diegosouzapw/awesome-omni-skill

Build production-ready Node.js backend services with Express/Fastify, implementing middleware patterns, error handling, authentication, database integration, and API design best practices. Use when creating Node.js servers, REST APIs, GraphQL backends, or microservices architectures.

nextjs-app-router-patterns

16
from diegosouzapw/awesome-omni-skill

Master Next.js 14+ App Router with Server Components, streaming, parallel routes, and advanced data fetching. Use when building Next.js applications, implementing SSR/SSG, or optimizing React Serve...

n8n-workflow-patterns

16
from diegosouzapw/awesome-omni-skill

Proven workflow architectural patterns from real n8n workflows. Use when building new workflows, designing workflow structure, choosing workflow patterns, planning workflow architecture, or asking about webhook processing, HTTP API integration, database operations, AI agent workflows, or scheduled tasks.

modern-javascript-patterns

16
from diegosouzapw/awesome-omni-skill

Master ES6+ features including async/await, destructuring, spread operators, arrow functions, promises, modules, iterators, generators, and functional programming patterns for writing clean, effici...

mcp-patterns

16
from diegosouzapw/awesome-omni-skill

MCP server building, advanced patterns, and security hardening. Use when building MCP servers, implementing tool handlers, adding authentication, creating interactive UIs, hardening MCP security, or debugging MCP integrations.

mapbox-integration-patterns

16
from diegosouzapw/awesome-omni-skill

Official integration patterns for Mapbox GL JS across popular web frameworks. Covers setup, lifecycle management, token handling, search integration, and common pitfalls. Based on Mapbox's create-web-app scaffolding tool.

linkerd-patterns

16
from diegosouzapw/awesome-omni-skill

Implement Linkerd service mesh patterns for lightweight, security-focused service mesh deployments. Use when setting up Linkerd, configuring traffic policies, or implementing zero-trust networking ...

langgraph-agent-patterns

16
from diegosouzapw/awesome-omni-skill

Implement multi-agent coordination patterns (supervisor-subagent, router, orchestrator-worker, handoffs) for LangGraph applications. Use when users want to (1) implement multi-agent systems, (2) coordinate multiple specialized agents, (3) choose between coordination patterns, (4) set up supervisor-subagent workflows, (5) implement router-based agent selection, (6) create parallel orchestrator-worker patterns, (7) implement agent handoffs, (8) design state schemas for multi-agent systems, or (9) debug multi-agent coordination issues.