Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

245
Vistas
Is there a way to query documents in mongoDB/mongoose to match ALL objects in an array property WHERE the datetime is greater than a specified date
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,
          },
       ]
   }]
}

Above is a snippet of the Schema

I want to be able to get documents where ALL Sessions object has a session_start_datetime greater than a specified date such as current date.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

YOURMODEL.find( { Sessions: { $all: [{session_start_datetime: {$gte: YOUR_DATE}] } } )

don't forget to pass YOUR_DATE in a correct Date format or it will not work.

example if your date is a string:

YOURMODEL.find( { Sessions: { $all: [{session_start_datetime: {$gte: new Date(YOUR_DATE)}] } } )
about 4 years ago · Juan Pablo Isaza Denunciar

0

Try:

model.find({
    'Course_Runs.Sessions.session_start_datetime': {
        $gt: current_date
    }
})
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda