const CourseSchema = new Schema({ course_name: { type: String, trim: true, }, Course_Runs: [ { run_id: { type: String, }, // This field is for Teachers that are involved in the course run teachers: [{ type: Schema.Types.ObjectId, ref: "users" }], // Course Date Duration will be an inferred field from first session and last session Sessions: [{ session_start_datetime: { type: Date, }, session_end_datetime: { type: Date, }, ] }] }Arriba hay un fragmento del esquema
Quiero poder obtener documentos en los que el objeto TODAS las sesiones tenga un session_start_datetime mayor que una fecha específica, como la fecha actual.
YOURMODEL.find( { Sessions: { $all: [{session_start_datetime: {$gte: YOUR_DATE}] } } )no olvide pasar YOUR_DATE en un formato de fecha correcto o no funcionará.
ejemplo si su fecha es una cadena:
YOURMODEL.find( { Sessions: { $all: [{session_start_datetime: {$gte: new Date(YOUR_DATE)}] } } )Probar:
model.find({ 'Course_Runs.Sessions.session_start_datetime': { $gt: current_date } })