Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

7MinutesDead-Git
Copy link

@7MinutesDead-Git 7MinutesDead-Git commented Sep 13, 2022

Check it out! Very simple comments implementation.

Also adds user name display to each post in the public feed.

- 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],
Copy link
Author

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],
Copy link
Author

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".

@7MinutesDead-Git
Copy link
Author

7MinutesDead-Git commented Sep 16, 2022

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

@7MinutesDead-Git 7MinutesDead-Git changed the title Comments mvp Comments mvp via embedded documents Sep 16, 2022
@7MinutesDead-Git 7MinutesDead-Git changed the title Comments mvp via embedded documents Comments via embedded documents within Post schema Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant