What should you decide up front in schema design?
Collections (entities), fields, types, constraints (required, unique, default, enum), indexes, and relationships (ref vs embed). All of these are hard to change after code is written.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Why You Should Design the Schema Before Coding
Because every layer depends on the schema. Once code is written against a schema, changing it forces changes in controllers, middlewares, validators, and frontend. Schema changes cascade through the codebase.
Use ref for one-to-many with large N (e.g., user and messages). Use embed for small, tightly coupled data that always loads together (e.g., an address inside a user). Embedding is fast but bloats documents; ref keeps them small.
Based on the queries you will run. If you often look up by email, add a unique index on email. If you often check if a request from A to B exists, add a compound unique index on (fromUserId, toUserId). Indexes serve queries.
Still have questions?
Browse all our FAQs or reach out to our support team
