Challenge - 5 Problems
Arithmetic Expressions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this MongoDB aggregation?
Given a collection with documents like {"value1": 10, "value2": 5}, what will be the result of this aggregation pipeline stage?
{ $project: { result: { $add: ["$value1", "$value2"] } } }MongoDB
{ $project: { result: { $add: ["$value1", "$value2"] } } }Attempts:
2 left
💡 Hint
Think about what $add does with two numbers.
✗ Incorrect
The $add operator sums the values of value1 and value2, so 10 + 5 = 15.
❓ query_result
intermediate2:00remaining
What does this $multiply expression return?
For documents with fields {"a": 4, "b": 3}, what is the output of this aggregation stage?
{ $project: { product: { $multiply: ["$a", "$b"] } } }MongoDB
{ $project: { product: { $multiply: ["$a", "$b"] } } }Attempts:
2 left
💡 Hint
Multiply the two numbers.
✗ Incorrect
4 multiplied by 3 equals 12.
📝 Syntax
advanced2:00remaining
Which option causes a syntax error in this $divide expression?
Identify which aggregation stage will cause a syntax error when trying to divide two fields:
{ $project: { ratio: { $divide: ["$num", "$den"] } } }MongoDB
{ $project: { ratio: { $divide: ["$num", "$den"] } } }Attempts:
2 left
💡 Hint
Check the number of arguments $divide expects.
✗ Incorrect
$divide requires exactly two arguments in an array. Option A provides a single string, causing a syntax error.
❓ query_result
advanced2:00remaining
What is the output of this nested arithmetic expression?
Given documents with {"x": 8, "y": 2, "z": 4}, what is the result of this aggregation stage?
{ $project: { result: { $add: [ { $multiply: ["$x", "$y"] }, { $divide: ["$z", 2] } ] } } }MongoDB
{ $project: { result: { $add: [ { $multiply: ["$x", "$y"] }, { $divide: ["$z", 2] } ] } } }Attempts:
2 left
💡 Hint
Calculate multiplication and division first, then add.
✗ Incorrect
Multiply 8*2=16, divide 4/2=2, then add 16+2=18.
🧠 Conceptual
expert2:00remaining
Why does this $divide operation return null?
Consider documents with {"a": 10, "b": 0}. What is the output of this aggregation stage?
Why does it return null instead of an error?
{ $project: { result: { $divide: ["$a", "$b"] } } }Why does it return null instead of an error?
MongoDB
{ $project: { result: { $divide: ["$a", "$b"] } } }Attempts:
2 left
💡 Hint
Think about how MongoDB handles invalid math operations.
✗ Incorrect
MongoDB returns null for division by zero to prevent pipeline failure.