0
0
MongoDBquery~5 mins

$eq for equality in MongoDB - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the $eq operator do in MongoDB?

The $eq operator checks if a field's value is equal to a specified value. It returns documents where the field matches exactly.

Click to reveal answer
beginner
How do you use $eq in a MongoDB query to find documents where age is 30?

You write: { age: { $eq: 30 } }. This finds documents where the age field equals 30.

Click to reveal answer
intermediate
Is { age: 30 } the same as { age: { $eq: 30 } } in MongoDB queries?

Yes, both find documents where age equals 30. The first is shorthand; the second uses $eq explicitly.

Click to reveal answer
intermediate
Can $eq be used to compare fields to null in MongoDB?

Yes, { field: { $eq: null } } finds documents where field is null or does not exist.

Click to reveal answer
beginner
What is the difference between $eq and $ne in MongoDB?

$eq checks for equality (equal to), while $ne checks for inequality (not equal to).

Click to reveal answer
What does { age: { $eq: 25 } } return in MongoDB?
ADocuments where age is greater than 25
BDocuments where age is not 25
CDocuments where age is 25
DDocuments where age is less than 25
Is { name: { $eq: "Alice" } } equivalent to { name: "Alice" }?
AYes, both find documents where name is Alice
BNo, they find different documents
COnly the first works
DOnly the second works
Which operator finds documents where a field is NOT equal to a value?
A$eq
B$gt
C$lt
D$ne
What happens if you query { score: { $eq: null } }?
AFinds documents where score is null or missing
BFinds documents where score is zero
CFinds documents where score is not null
DReturns an error
Which is a correct way to find documents where status equals "active"?
A{ status: "active" }
BBoth B and C
C{ status: { $eq: "active" } }
DNeither B nor C
Explain how the $eq operator works in MongoDB queries.
Think about how you find items that exactly match a value.
You got /3 concepts.
    Describe the difference between using $eq and not using it in a MongoDB query.
    Consider if <code>{ age: 30 }</code> and <code>{ age: { $eq: 30 } }</code> return the same documents.
    You got /3 concepts.