Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
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 answers
Answer question

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 Report

0

Try:

model.find({
    'Course_Runs.Sessions.session_start_datetime': {
        $gt: current_date
    }
})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!