I have the following Schema for a virtual classroom in mongoose:
var classroomSchema = mongoose.Schema({
studentIds: [mongoose.Schema.Types.ObjectId],
teacherIds: [mongoose.Schema.Types.ObjectId],
teacherNames: [String],
createdAt: {
type: Date,
default: Date.now(),
},
lessons: [{
name: String,
startDate: {
type: Date,
min: Date.now(),
},
endDate: {
type: Date,
min: Date.now(),
},
**expiresAt: endDate,**
}],
});
I want each lesson to expire from the classroom after theer endDate has passed. How can I use TTLs in subdocuments in mongoose?