-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments via embedded documents within Post schema #7
base: main
Are you sure you want to change the base?
Conversation
- Move Return To Feed button above feed, as the button would be hard to find after the user had many posts.
- Add comment post route based on post id. - Add commentPost() method to posts controller. - Add userName and comments fields to Post schema. - Add comments section and input form to post view. - Add userName (author) display to each post in public feed.
- Add Comment schema as embedded document within Post schema (since comments will only ever be associated with a particular post). - Add replies to comment schema, as embedded array of comment schemas (recursive "this"), e.g., each reply is also a Comment. - Add port to server console on startup.
type: Array, | ||
required: false | ||
}, | ||
comments: [Comments.schema], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where you can add Comments Schema as an embedded document to the Post Schema, to save yourself from additional queries after first querying for your Post.
You automatically get the Comments associated with that Post, just by querying the Post.
default: Date.now, | ||
}, | ||
replies: { | ||
type: [this], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is where you can recursively add Comment replies as arrays of Comments (who will then each have their own Comment replies array), by referencing "this".
Adjusted some of the schema approach after stream. I think it's better to do comments as an array of embedded documents, rather than having a whole other collection of comments, since comments are only ever contained within a specific post. This means you can make one query for the post as usual and you automatically get the comments associated with it, rather than needing to do two separate queries for the post and then the comments with a matching post ID. Check the comments above for examples |
Check it out! Very simple comments implementation.
Also adds user name display to each post in the public feed.