Recall & Review
beginner
What does the
$lt operator do in MongoDB?The $lt operator finds documents where the value of a field is less than a specified value.
Click to reveal answer
beginner
How is
$lte different from $lt in MongoDB?$lte means "less than or equal to" while $lt means strictly "less than". $lte includes the value itself.
Click to reveal answer
beginner
Write a MongoDB query to find all documents where the field
age is less than 30.{ "age": { "$lt": 30 } }Click to reveal answer
beginner
Write a MongoDB query to find all documents where the field
score is less than or equal to 100.{ "score": { "$lte": 100 } }Click to reveal answer
beginner
Why would you use
$lt or $lte in a real-life database search?To find items with values below a limit, like products cheaper than $50 ($lt) or students with grades up to 70 ($lte).
Click to reveal answer
Which operator finds documents where a field is strictly less than a value?
✗ Incorrect
$lt means less than, excluding the value itself.
What does
{ "price": { "$lte": 20 } } find?✗ Incorrect
$lte means less than or equal to, so prices up to 20 are included.
Which query finds documents where
age is less than 18?✗ Incorrect
$lt finds values strictly less than 18.
If you want to include the value 50 in your search for less than or equal, which operator do you use?
✗ Incorrect
$lte includes the value itself in the results.
Which operator would NOT be used to find values less than a number?
✗ Incorrect
$gt means greater than, so it does not find less than values.
Explain the difference between
$lt and $lte in MongoDB queries.Think about whether the boundary value itself is included or not.
You got /3 concepts.
Write a MongoDB query to find all documents where the field
temperature is less than or equal to 0.Use the $lte operator with the field and value.
You got /4 concepts.