Sequence NODE_271
MediumReference Author from Post Document
MongoDB
Technical Specification
Design blog posts collection where each post stores a reference (userId) to the author in users collection.
Input/Output Samples
Input:New post
Output:{ title, body, userId:ObjectId, createdAt }
Optimal Logic Path
db.posts.insertOne({
title: "My first blog",
body: "Content here...",
userId: ObjectId("60a7..."),
createdAt: new Date(),
});
// index for userId
db.posts.createIndex({ userId: 1 });Architectural Deep-Dive
Referencing keeps collections separate but connected via IDs, useful when author data is reused widely.