MongoDB Schema Design Cheat Sheet

Embeds, references, and shard keys

Last Updated: November 21, 2025

Focus Areas

Focus
Align shard keys with query patterns and cardinality
Rely on embedding when atomic updates are needed

Commands & Queries

db.collection.createIndex({ customerId: 1 })
Add an index
db.collection.explain().find({ ... })
Review query plan
sh.status()
Inspect sharding topology

Summary

Model documents for your access patterns and shard with intent.

💡 Pro Tip: Favor embedding for read-heavy collections and reference for many-to-many.
← Back to Databases & APIs | Browse all categories | View all cheat sheets