In Node.js, the express framework-based database uses MongoDB.
However, it was not as easy as I thought how to implement the comments and subcomments.
Can I get advice from people who have implemented or experienced these features?
node.js back-end javascript mongodb
Your question is about one-to-many relationship.
One post can have multiple comments and each comment can have multiple comments. However, one comment does not have multiple posts, and likewise, one comment cannot have multiple comments and sub-comments. So if you refer to the official document or these articles, you can roughly organize them like this.
/* Strategy */
{
_id: 102,
comment: "You know..."
/* Skipping */
subcomments: [103, 105, 111, 156] /* comments processed as subcomments._ids */
},
{
_id: 103,
comment: "ㄴLOL",
/* Skipping */
subcomments: null /* If there are no subcomments or deleted, remove the key or null */
},
/* Skipping */
© 2024 OneMinuteCode. All rights reserved.