How to make comments to the comments?

It is not quite clear how the figures in this case. An example can be found at reddit https://www.reddit.com/r/news/comments/9my7g1/cana...

In addition to the actual comments to the post, there are branches of the responses to specific comments. How to organize it in terms of a data model?

For example, I have model Post and Comment

const postSchema = new mongoose.Schema ({
 author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
 slug: {
 type: String,
 unique: true
},
 title: {
 type: String
},
 createdAt: {
 type: Date,
 default: Date.now
},
 comments: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Comment' }],
 contributors: [{ type: mongoose.Schema.Types.ObjectId, ref: 'User' }]
})

const commentSchema = new mongoose.Schema ({
 author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
 text: {
 type: String
},
 createdAt: {
 type: Date,
 default: Date.now
},
 post: { type: mongoose.Schema.Types.ObjectId, ref: 'Post' }
})


How to be with nested comments?
March 12th 20 at 08:09
0 answer

Find more questions by tags MongooseMongoDB