MongoDB is a comment system. How should the data table structure be designed?

  mongodb, question

The general comment system is as follows:

Articles-> comments of articles-> comments of comments, mysql is used as two tables, articles and comments tables, and “comments of articles” and “comments of comments” are stored in one table comments.

Question:
So, how to design the data table structure when mongodb is used to do the same thing?

Mongo is very suitable for doing such a thing. The following article sets out a comment structure.

General structure:

{
 title: String,
 content: String,
 createTime: DateTime,
 comments: [
 userName: String,
 //Consider that only the first level of nesting is stored here.  Comments in the nest exist as JSON strings (assuming more reads than writes, this is efficient for queries).  )
 content: String
 ]
 }

However, it still depends on the demand.

  1. Whether the comment appears as a separate concept. For example, some statistics for comments.
  2. Whether comments are nested infinitely.
  3. Whether the comments need to be revised frequently, such as praising.