0
0
MongoDBquery~5 mins

Comparison expressions ($eq, $gt in aggregation) in MongoDB - Cheat Sheet & Quick Revision

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

The $eq operator checks if two values are equal. It returns true if they are the same, otherwise false.

Click to reveal answer
beginner
How does the $gt operator work in MongoDB aggregation?

The $gt operator checks if the first value is greater than the second value. It returns true if it is, otherwise false.

Click to reveal answer
beginner
Write a simple MongoDB aggregation expression using $eq to check if the field status equals "active".
{ $eq: ["$status", "active"] }
Click to reveal answer
beginner
In aggregation, what type of value do $eq and $gt return?

Both $eq and $gt return a boolean value: true or false.

Click to reveal answer
intermediate
Why are comparison expressions like $eq and $gt useful in MongoDB aggregation?

They help filter or create conditions inside aggregation pipelines, allowing you to compare values and decide which documents to include or how to transform data.

Click to reveal answer
What does { $eq: ["$age", 30] } check in an aggregation pipeline?
AIf the field <code>age</code> is greater than 30
BIf the field <code>age</code> is not equal to 30
CIf the field <code>age</code> is less than 30
DIf the field <code>age</code> equals 30
Which operator would you use to check if a value is greater than another in MongoDB aggregation?
A$gt
B$ne
C$lt
D$eq
What type of value do $eq and $gt return in aggregation?
ANumber
BString
CBoolean
DArray
In the expression { $gt: ["$score", 50] }, what does it mean if the result is true?
AThe score equals 50
BThe score is greater than 50
CThe score is less than 50
DThe score is not a number
Which of these is a valid use of $eq in an aggregation pipeline?
A{ $eq: ["$price", 100] }
B{ $eq: "$price", 100 }
C{ $eq: "$price" }
D{ $eq: [100] }
Explain how the $eq and $gt operators work in MongoDB aggregation and give a simple example of each.
Think about comparing values and returning true or false.
You got /4 concepts.
    Describe a real-life situation where you might use $eq and $gt in a MongoDB aggregation pipeline.
    Imagine sorting or filtering data like a list of users or products.
    You got /3 concepts.