Example: If I delete a user, I want to also remove all of that users associated comments.
const UserSchema = new Schema(
{
username: {
type: String,
unique: true,
},
email: {
type: String,
unique: true,
},
comments: [
{
type: Schema.Types.ObjectId,
ref: "Comment"
}
],
);
Right now I am removing a user with the .findOneAndDelete method.