π 27 Jul 2025
View on Github βSpent over 13 hours building & testing a full nested answer system for threaded conversations β like Twitter/X replies.
Feature | Status |
---|---|
π¦ Self-referencing schema | β Done |
π Recursive delete logic | β Implemented |
π₯ Efficient thread fetching | β Built & tested |
π§ Clean schema + indexing | β Structured |
π» Manual testing | β Covered with edge cases |
{
_id: ObjectId,
content: String,
questionId: ObjectId,
parentAnswerId: ObjectId, // null if it's a top-level answer
userId: ObjectId,
replies: [ObjectId], // for faster lookup
...
}
Each answer can reference another answer, forming a tree. Top-level answers have
parentAnswerId = null
.
await deleteAllReplies(answerId); // depth-first traversal
Prevents orphaned replies and ensures clean data.
populate()
+ indexed parentAnswerId
π§ Concept Design:
ποΈ DB Schema Diagram:
π» Live Testing Screenshot:
This was hard but incredibly rewarding. I now understand:
βYou donβt learn recursion from LeetCode β you learn it when building a threaded system from scratch.β