Skip to content

Instantly share code, notes, and snippets.

@ats1999
Created October 15, 2021 08:19
Show Gist options
  • Save ats1999/0708529393bfd2910713a39b760b9583 to your computer and use it in GitHub Desktop.
Save ats1999/0708529393bfd2910713a39b760b9583 to your computer and use it in GitHub Desktop.
blog-comment-schema

UI

comment_page-0001

You can see from the UI, there is a post and some comments. Few comments have threads

Tech stack

NodeJs, MongoDB

Current Schema

// blogPostSchema
{
    _id:"..",
    title:"..",
    ...,
    comments:[
        {
            authorId:"..",
            body:"Some markdown content or simple text",
            threads:[], // no thread as of now
            ts:123123, // time stamp (Unix)
        },
        {
            authorId:"..",
            body:"Some markdown content or simple text",
            threads:[
                // a thread can not contain any other thread
                {
                    authorId:"..",
                    body:"Thread 1",
                    ts:123123, // time stamp (Unix)
                }
            ], 
            ts:123123, // time stamp (Unix)
        }
    ]
}

You can see from the above schema that a post can have any number of comments and a comment can have any number of thread.

But, a thread can not have nested thread

Which funcanility i want

Comment

  • a user can create comment
  • a user can edit comment
  • a user can delete comment (Author only)

Thread

  • a user can create thread on a comment
  • a user can edit thread on a comment
  • a user can delete thread of a comment (Author only)

Extra

I want to get few information of the author of comment or thread, like name, pic, reputation etc.

Please sugggest an schema or any other way to achive this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment