Using String Expressions in MongoDB Aggregation
📖 Scenario: You work in a small bookstore's database team. The store keeps records of books with separate fields for the author's first name and last name. You want to create a new field that shows the author's full name in uppercase letters for better display on the website.
🎯 Goal: Build a MongoDB aggregation pipeline that combines the author's first and last names into a single full name string, converts it to uppercase, and stores it in a new field called authorFullName.
📋 What You'll Learn
Create a collection named
books with documents containing authorFirstName and authorLastName fields.Add a configuration variable
space that holds a single space character.Use the
$concat expression to join the first name, space, and last name into one string.Use the
$toUpper expression to convert the concatenated full name to uppercase.Add the resulting uppercase full name as a new field
authorFullName in the aggregation output.💡 Why This Matters
🌍 Real World
Bookstores and libraries often store author names in separate fields. Combining and formatting these names helps display them nicely on websites and reports.
💼 Career
Database developers and data engineers frequently use string expressions in MongoDB aggregation pipelines to transform and prepare data for applications.
Progress0 / 4 steps