0
0
MongoDBquery~20 mins

$lt and $lte for less than in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Less Than Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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 } })
Adb.users.find({ age: { $gt: 30 } })
Bdb.users.find({ age: { $lte: 30 } })
Cdb.users.find({ age: { $lt: 30 } })
Ddb.users.find({ age: { $gte: 30 } })
Attempts:
2 left
💡 Hint
Remember, $lt means strictly less than, while $lte means less than or equal to.
query_result
intermediate
2: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 } })
Adb.products.find({ price: { $lte: 100 } })
Bdb.products.find({ price: { $lt: 100 } })
Cdb.products.find({ price: { $gt: 100 } })
Ddb.products.find({ price: { $gte: 100 } })
Attempts:
2 left
💡 Hint
Check if the query includes products priced exactly at 100.
📝 Syntax
advanced
2: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 } })
Adb.scores.find({ score: { $lt: '50' } })
Bdb.scores.find({ score: { $lt: 50 } })
Cdb.scores.find({ score: { $lte: 50 } })
Ddb.scores.find({ score: { $lt 50 } })
Attempts:
2 left
💡 Hint
Check the syntax for specifying operators and values in MongoDB queries.
query_result
advanced
2: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') } })
Adb.events.find({ date: { $lt: new Date('2023-01-01') } })
Bdb.events.find({ date: { $lte: new Date('2023-01-01') } })
Cdb.events.find({ date: { $gt: new Date('2023-01-01') } })
Ddb.events.find({ date: { $gte: new Date('2023-01-01') } })
Attempts:
2 left
💡 Hint
Remember that $lte includes the date itself.
🧠 Conceptual
expert
2: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 } })?
AThe first query returns 2 documents; the second returns 3 documents
BBoth queries return 2 documents
CThe first query returns 3 documents; the second returns 2 documents
DBoth queries return 3 documents
Attempts:
2 left
💡 Hint
Think about whether the value 30 is included in each query.