Schema Design Tips

View saved

Model for your queries

Design around how you read and write data, not only how entities relate on a whiteboard.

Embed when data travels together

  • User profile settings loaded with the user
  • Order line items usually shown with the order
  • Small, bounded arrays

Reference when shared or large

  • Authors shared by many books
  • Huge comment histories better as separate collections
  • Data updated independently on different schedules

Avoid unbounded growth

A document that grows forever (append-only logs inside one doc) becomes hard to update and transfer. Cap arrays or move history out.

// Prefer referencing for large shared data
{ "title": "Book", "authorId": ObjectId("...") }

Comments

One comment per signed-in account. Comments are saved with this page’s URL.