Refs in Mongoose. A ref field stores an ObjectId and references another model. Without refs, you cannot do populate or handle relationships. This is the foundation.
What should I learn first about APIs with relationships?
More FAQs in Roadmap for Writing APIs With Relationships in Node.js
Understand refs, learn populate, learn the N+1 problem, learn nested populate, learn virtual populate, learn embed vs reference, learn denormalization, learn cascade deletes, learn side-loading, learn indexing for refs, learn pagination with populate, and test.
After populate and the N+1 problem. Denormalization is for high-traffic reads where populate is too slow. You copy key fields (author name on the post) and decide whether to update on change or accept staleness.
After basic CRUD and relationships. When you delete a user, their posts and messages should go too. Use deleteMany for each related collection. Do it in a transaction if your MongoDB supports it.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.