$gt, $gte, $lt, $lte — MongoDB Technical Interview Questions & Answers

Greater-than / less-than range comparison operators.

$gt, $gte, $lt, $lte

  • Simple meaning: $gt greater than, $gte ≥, $lt less than, $lte ≤. Range filters on numbers or dates.
  • How to use: db.students.find({ marks: { $gt: 40 } }) pass marks. Range: { marks: { $gte: 40, $lte: 80 } }.
  • Try this: insert marks 38 and 72, find $gt 40 — only 72 should appear.
  • Common mistake: { marks: > 40 } — invalid. Must be { marks: { $gt: 40 } }.
  • Interview tip: Range query + mention an index on that field for large collections.

Technical Interview Tip: Write one $gt filter on marks.

Code Examples for $gt, $gte, $lt, $lte

$gt, $gte, $lt, $lte — working example

db.users.find({ age: { $gte: 18, $lt: 60 } })
db.orders.find({ amount: { $gt: 50 } })

$gt, $gte, $lt, $lte — comparison operators filter ranges: $gt/$gte/$lt/$lte.

How to Explain $gt, $gte, $lt, $lte to an Interviewer

How do you find marks above 40?

db.students.find({ marks: { $gt: 40 } })