Recall & Review
beginner
What does the
$concat expression do in MongoDB?It joins two or more strings together into one string.
Click to reveal answer
beginner
How does
$toUpper transform a string in MongoDB?It changes all letters in the string to uppercase letters.
Click to reveal answer
beginner
What is the purpose of
$toLower in MongoDB string expressions?It converts all letters in a string to lowercase letters.
Click to reveal answer
intermediate
Write a MongoDB expression to combine first name and last name with a space in between.
Use
{ $concat: ["$firstName", " ", "$lastName"] } to join firstName and lastName with a space.Click to reveal answer
intermediate
How can you convert a user's name to uppercase and then concatenate with a greeting in MongoDB?
Use
{ $concat: ["Hello, ", { $toUpper: "$name" }] } to greet with uppercase name.Click to reveal answer
Which MongoDB expression joins multiple strings into one?
✗ Incorrect
$concat joins strings; $toUpper and $toLower change case; $split breaks strings apart.What does
$toUpper do to the string "hello"?✗ Incorrect
$toUpper converts all letters to uppercase.How would you convert "WORLD" to lowercase in MongoDB?
✗ Incorrect
$toLower changes all letters to lowercase.Which expression correctly joins firstName and lastName with a space?
✗ Incorrect
You need to add a space string " " between the two fields in
$concat.What will this expression return? { $concat: ["Hi, ", { $toUpper: "$user" }] } if user is "anna"?
✗ Incorrect
It concatenates "Hi, " with the uppercase version of "anna", which is "ANNA".
Explain how to use $concat, $toUpper, and $toLower in MongoDB to format a full name.
Think about joining first and last names and changing case.
You got /4 concepts.
Describe a real-life example where $concat and $toUpper could be used together in a MongoDB query.
Imagine saying hello to a user with their name in capital letters.
You got /3 concepts.