Challenge - 5 Problems
String Expression 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 pipeline?
Consider the following document in a collection:
{ "firstName": "Alice", "lastName": "Smith" }What will be the value of the field fullName after running this pipeline?[{ $project: { fullName: { $concat: ["$firstName", " ", { $toUpper: "$lastName" }] } } }]MongoDB
[{ $project: { fullName: { $concat: ["$firstName", " ", { $toUpper: "$lastName" }] } } }]Attempts:
2 left
💡 Hint
Remember that $toUpper converts the string to uppercase letters.
✗ Incorrect
The $concat operator joins the firstName, a space, and the lastName converted to uppercase. So lastName 'Smith' becomes 'SMITH'.
❓ query_result
intermediate2:00remaining
What does this aggregation pipeline output for the field
greeting?Given a document:
{ "name": "bob" }Run this pipeline:[{ $project: { greeting: { $concat: ["Hello, ", { $toUpper: { $substrCP: ["$name", 0, 1] } }, { $toLower: { $substrCP: ["$name", 1, 2] } }] } } }]MongoDB
[{ $project: { greeting: { $concat: ["Hello, ", { $toUpper: { $substrCP: ["$name", 0, 1] } }, { $toLower: { $substrCP: ["$name", 1, 2] } }] } } }]Attempts:
2 left
💡 Hint
Look at how the first letter is uppercased and the rest lowercased.
✗ Incorrect
The pipeline capitalizes the first letter of the name and lowercases the next two letters, resulting in 'Bob'.
📝 Syntax
advanced2:00remaining
Which option causes a syntax error in this MongoDB aggregation expression?
Identify the option that will cause a syntax error when used inside a $project stage:
{ fullName: { $concat: ["$firstName", " ", $toUpper: "$lastName" ] }MongoDB
{ fullName: { $concat: ["$firstName", " ", $toUpper: "$lastName" ] } }Attempts:
2 left
💡 Hint
Check how $toUpper is wrapped inside the $concat array.
✗ Incorrect
Option C is missing curly braces around $toUpper expression, causing a syntax error.
❓ optimization
advanced2:00remaining
Which option is the most efficient way to concatenate first and last names in uppercase?
You want to create a field
Which pipeline stage is best?
fullNameUpper that combines firstName and lastName in uppercase letters.Which pipeline stage is best?
Attempts:
2 left
💡 Hint
Applying $toUpper once after concatenation is usually more efficient.
✗ Incorrect
Option B applies $toUpper once on the whole concatenated string, reducing function calls and improving performance.
🧠 Conceptual
expert3:00remaining
What will be the output of this aggregation pipeline for the field
result?Given a document:
{ "word": "MongoDB" }Run this pipeline:[{ $project: { result: { $concat: [ { $toLower: { $substrCP: ["$word", 0, 3] } }, { $toUpper: { $substrCP: ["$word", 3, 3] } }, { $toLower: { $substrCP: ["$word", 6, 2] } } ] } } }]MongoDB
[{ $project: { result: { $concat: [ { $toLower: { $substrCP: ["$word", 0, 3] } }, { $toUpper: { $substrCP: ["$word", 3, 3] } }, { $toLower: { $substrCP: ["$word", 6, 2] } } ] } } }]Attempts:
2 left
💡 Hint
Look carefully at the substring positions and lengths.
✗ Incorrect
The first 3 letters 'Mon' become 'mon', next 3 letters 'goD' become 'GOD', last 2 letters 'b' plus one extra character (empty) become 'b'. So result is 'monGODb'.