When should I decide ref vs embed in schema design?
After listing fields and types, before adding indexes. For each relationship, decide: ref for large N (messages, connections), embed for small tightly coupled data (an address in a user). This decision is hard to change later.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in MongoDB Schema Design Roadmap: From Idea to Production
List entities, list fields, pick types, add validation, add defaults, decide ref vs embed, add indexes, add timestamps, mark sensitive fields, write the schema file, add hooks, test, use in routes, and monitor in production.
After entities, fields, types, validation, defaults, and ref vs embed. Index the queries you actually run. Use explain() to verify. Add more indexes as the data grows and query patterns emerge in production.
Write tests that try to save invalid data. Confirm validation rejects bad data. Confirm unique indexes reject duplicates. Confirm hooks run (e.g., password gets hashed on save). Tests catch schema bugs early.
Still have questions?
Browse all our FAQs or reach out to our support team
