The properties firstName and lastName are inside a profile object so don’t need to do any $reduce or $map operators, look at the below pipeline, it will cut the first character from the string and make it upper case and concat with next characters,
db.hej.aggregate([
{
$set: {
"profile.firstName": {
$concat: [
{ $toUpper: { $substr: ["$profile.firstName", 0, 1] } },
{ $substr: ["$profile.firstName", 1, { $strLenCP: "$profile.firstName" }] }
]
},
"profile.lastName": {
$concat: [
{ $toUpper: { $substr: ["$profile.lastName", 0, 1] } },
{ $substr: ["$profile.lastName", 1, { $strLenCP: "$profile.lastName" }] }
]
}
}
}
])