0
0
MongoDBquery~20 mins

$eq for equality in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
MongoDB $eq Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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 } })
Adb.users.find({ age: { $eq: "30" } })
Bdb.users.find({ age: { $eq: 30 } })
Cdb.users.find({ age: 30 })
Ddb.users.find({ $eq: { age: 30 } })
Attempts:
2 left
💡 Hint
Use $eq to match the exact value and type.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in $eq usage
Which of the following MongoDB queries has a syntax error when using $eq?
Adb.collection.find({ $eq: { field: 10 } })
Bdb.collection.find({ field: { $eq: "value" } })
Cdb.collection.find({ field: { $eq: 10 } })
Ddb.collection.find({ field: 10 })
Attempts:
2 left
💡 Hint
Check the position of $eq operator in the query.
query_result
advanced
2: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"?
Adb.collection.find({ address: { city: { $eq: "New York" } } })
Bdb.collection.find({ "address.city": "New York" })
Cdb.collection.find({ "address.city": { $eq: "New York" } })
Ddb.collection.find({ $eq: { "address.city": "New York" } })
Attempts:
2 left
💡 Hint
Use dot notation to query nested fields with $eq.
optimization
advanced
2:00remaining
Optimize query using $eq for exact match
Which query is the most efficient to find documents where status equals "active"?
Adb.collection.find({ status: { $in: ["active"] } })
Bdb.collection.find({ status: { $eq: "active" } })
Cdb.collection.find({ $eq: { status: "active" } })
Ddb.collection.find({ status: "active" })
Attempts:
2 left
💡 Hint
Consider the simplest form for exact equality in MongoDB.
🧠 Conceptual
expert
3: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 } })
AReturns documents where score is the number 10 only
BReturns documents where score is the string "10" only
CReturns documents where score is either number 10 or string "10"
DReturns no documents because of type mismatch
Attempts:
2 left
💡 Hint
MongoDB $eq matches both value and type exactly.