MongoDB — Mongoose Population & References
Link collections using Schema ObjectId references and resolve relationships with .populate().
1Using Mongoose populate()
Mongoose Population
// Post Schema referencing User
const postSchema = new mongoose.Schema({
title: String,
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }
});
const Post = mongoose.model('Post', postSchema);
// Populate author details in post query
const post = await Post.findById(postId).populate('author', 'name email');