Challenge - 5 Problems
MongoDB $eq Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Find documents where age equals 30
Given a collection users with documents containing an
age field, which query returns all users whose age is exactly 30?MongoDB
db.users.find({ age: { $eq: 30 } })Attempts:
2 left
💡 Hint
Use $eq to match the exact value and type.
✗ Incorrect
Option B correctly uses $eq to match age exactly as number 30. Option B uses string "30" which won't match number 30. Option B works but does not explicitly use $eq operator. Option B has wrong syntax for $eq usage.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in $eq usage
Which of the following MongoDB queries has a syntax error when using $eq?
Attempts:
2 left
💡 Hint
Check the position of $eq operator in the query.
✗ Incorrect
Option A incorrectly places $eq as the top-level key with a nested field, which is invalid syntax. $eq must be inside the field's condition object.
❓ query_result
advanced2:00remaining
Find documents with nested field equal to a value
Given documents with a nested field
address.city, which query returns documents where city equals "New York"?Attempts:
2 left
💡 Hint
Use dot notation to query nested fields with $eq.
✗ Incorrect
Option C correctly uses dot notation with $eq to match nested field. Option C incorrectly nests $eq inside an object without dot notation. Option C works but does not explicitly use $eq. Option C has invalid syntax.
❓ optimization
advanced2:00remaining
Optimize query using $eq for exact match
Which query is the most efficient to find documents where
status equals "active"?Attempts:
2 left
💡 Hint
Consider the simplest form for exact equality in MongoDB.
✗ Incorrect
Option D is the simplest and most efficient query for exact match. Option D uses $eq but adds unnecessary complexity. Option D has invalid syntax. Option D uses $in which is less efficient for single value match.
🧠 Conceptual
expert3:00remaining
Understanding $eq behavior with different data types
What will be the result of this query if the collection has documents with
score as both string and number types?db.collection.find({ score: { $eq: 10 } })Attempts:
2 left
💡 Hint
MongoDB $eq matches both value and type exactly.
✗ Incorrect
The $eq operator matches both value and type. So only documents with score as number 10 match, not string "10".