Relationships in mongo
Course: MongoDB, Zod, Error handling and Input validation - chapter 13
In MongoDB, data is related across collections using something called references
In our TODO application, each todo refers to an entry in the users table.

Our original schema
Section titled “Our original schema”const Todo = new Schema({ userId: ObjectId, title: String, done: Boolean});Update schema with references
Section titled “Update schema with references”const TodoSchema = new Schema({ userId: { type: Schema.Types.ObjectId, ref: 'users' }, title: String, done: Boolean});Benefits?
Section titled “Benefits?”You can pre-populate fields like user information since you’ve defined the exact relationship
app.get("/todos", auth, async function(req, res) { const userId = req.userId;
const todos = await TodoModel.find({ userId }).populate('userId').exec();
res.json({ todos })});