Facebook Pixel

How do I decide which indexes to create?

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.

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.

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.

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.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.