Skip to content
Back to skills

Nosql Patterns

ASecurity

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

  • 57 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 17, 2026
databasesjavascriptgojavasqlawsdatabaseperformancedocumentation

Security analysis

A100/100

Scanned October 17, 2026

npx -y skills add diegosouzapw/awesome-omni-skill --skill nosql-patterns --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Nosql Patterns?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Nosql Patterns
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/diegosouzapw-nosql-patterns/badge)](https://www.skillsdirectory.com/skills/diegosouzapw-nosql-patterns)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: NoSQL Patterns
description: "Các mẫu tối ưu cho cơ sở dữ liệu NoSQL (MongoDB, Redis và hệ phân tán đa)."
category: Database
difficulty: Intermediate
last_updated: 2026-01-16
---

# 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/)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.