Challenge - 5 Problems
Less Than Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Find documents with age less than 30
Given a collection
users with documents containing an age field, which query returns all users younger than 30?MongoDB
db.users.find({ age: { $lt: 30 } })Attempts:
2 left
💡 Hint
Remember, $lt means strictly less than, while $lte means less than or equal to.
✗ Incorrect
The $lt operator selects documents where the value is strictly less than the specified number. Here, it returns users with age less than 30.
❓ query_result
intermediate2:00remaining
Find documents with price less than or equal to 100
Which query returns all products with a price less than or equal to 100?
MongoDB
db.products.find({ price: { $lte: 100 } })Attempts:
2 left
💡 Hint
Check if the query includes products priced exactly at 100.
✗ Incorrect
The $lte operator includes values less than or equal to the specified number, so products priced at 100 are included.
📝 Syntax
advanced2:00remaining
Identify the syntax error in this query
Which option contains a syntax error when trying to find documents with score less than 50?
MongoDB
db.scores.find({ score: { $lt 50 } })Attempts:
2 left
💡 Hint
Check the syntax for specifying operators and values in MongoDB queries.
✗ Incorrect
Option D is missing the colon : between $lt and the value, causing a syntax error.
❓ query_result
advanced2:00remaining
Find documents with date less than or equal to a specific date
Given documents with a
date field, which query returns all documents with date less than or equal to January 1, 2023?MongoDB
db.events.find({ date: { $lte: new Date('2023-01-01') } })Attempts:
2 left
💡 Hint
Remember that $lte includes the date itself.
✗ Incorrect
The $lte operator includes documents where the date is exactly January 1, 2023, or earlier.
🧠 Conceptual
expert2:00remaining
Understanding difference between $lt and $lte in query results
If a collection
items has documents with a numeric field value containing values 10, 20, 30, and 40, what is the number of documents returned by db.items.find({ value: { $lt: 30 } }) compared to db.items.find({ value: { $lte: 30 } })?Attempts:
2 left
💡 Hint
Think about whether the value 30 is included in each query.
✗ Incorrect
The $lt query returns documents with values less than 30 (10 and 20), so 2 documents. The $lte query includes 30 as well, so it returns 3 documents.