querydrill

Learn ›MongoDB fundamentals ›Query operators

Comparison operators

comparisonfind()$gte$lt

These are the operators you should be able to write without thinking. The one detail worth memorising: two conditions on the same field go inside the same object.

$gt   // greater than
$gte  // greater than or equal
$lt
$lte
$ne
$in
$nin

Example:

db.users.find({
  age: {
    $gte: 25,
    $lt: 40
  }
})

Meaning:

25 <= age < 40

Practise this

1 exercise