Challenge - 5 Problems
String and Number Types Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Find documents with numeric string values
Given a collection
products where the field price is stored as a string, which query returns all documents where price is a string representing a number greater than 100?MongoDB
db.products.find({ price: { $gt: "100" } })Attempts:
2 left
💡 Hint
Remember that comparing strings with $gt compares lexicographically.
✗ Incorrect
Since
price is stored as a string, the query must compare strings. Using $gt: "100" compares string values lexicographically, which matches strings greater than "100".📝 Syntax
intermediate2:00remaining
Identify the correct syntax for storing a number as a string
Which of the following MongoDB insert commands correctly stores the field
age as a string with value "30"?Attempts:
2 left
💡 Hint
Strings must be enclosed in quotes.
✗ Incorrect
To store
age as a string, the value must be enclosed in quotes. Option C uses "30" which is a string literal.🧠 Conceptual
advanced2:00remaining
Understanding BSON types for numbers and strings
In MongoDB, which BSON type is used to store a 64-bit integer number?
Attempts:
2 left
💡 Hint
Think about the size and precision of the number type.
✗ Incorrect
MongoDB uses the
Int64 (also called Long) BSON type to store 64-bit integer numbers exactly.🔧 Debug
advanced2:00remaining
Why does this query not return expected numeric results?
Consider the collection
sales where amount is stored as a string. The query db.sales.find({ amount: { $gt: 100 } }) returns no documents. Why?MongoDB
db.sales.find({ amount: { $gt: 100 } })Attempts:
2 left
💡 Hint
Check the data type of the field and the query value.
✗ Incorrect
MongoDB does not convert types automatically in queries. Comparing a string field with a number value does not match any documents.
❓ optimization
expert2:00remaining
Optimizing queries on numeric strings
You have a collection
orders where the field quantity is stored as a string. You want to efficiently find all orders with quantity greater than 50. Which approach is best?Attempts:
2 left
💡 Hint
Think about data types and indexing for performance.
✗ Incorrect
Storing numeric data as strings prevents efficient numeric queries and indexing. Converting the field to a numeric type and indexing it improves query speed and correctness.