Post collection
Post :
_id : 001,
comments : [1,2,3] // ObjectId
Comment collection
Comment:
{ _id : 1, message : "Bar" },
{ _id : 2, message : "Foo" },
{ _id : 3, message : "Bazz" }
I want to delete a Post and all comments on this post. But How to delete all its comments ?
Update
PostSchema
{
model: String,
stock: Number,
images: [String],
price: Number,
views: { type: Number, default: 1 },
commentsCount: { type: Number, default: 0 },
comments: [{ type: Schema.Types.ObjectId, ref: "postComments" }],
postedBy: { type: String, ref: "publisherInfo" }
},
postComments Schema
{
sender: String,
createAt: { type: Date, default: Date.now },
votes: { type: Number, default: 0 },
contain: String
},