Nejprve musíte $unwind
employee
pak můžete použít $concat
spojit dvě pole.
db.loggableUser.aggregate([
{ '$lookup': {
'from': 'employees',
'localField': 'employee',
'foreignField' : '_id',
'as': 'employee'
}},
{ '$unwind': '$employee' },
{ '$addFields': {
'employee.fullName' : { '$concat': ['$employee.name' + ' ' + '$employee.surname'] }
}}
])
Což je mnohem jednodušší s mongodb 3.6 a výše $lookup
syntaxe.
db.loggableUser.aggregate([
{ '$lookup': {
'from': 'employees',
'let': { 'employee': '$employee' },
'pipeline': [
{ '$match': { '$expr': { '$eq': ['$_id', '$$employee'] }}},
{ '$addFields': { 'fullName' : { '$concat': ['$name', ' ', '$surname'] }}}
]
'as': 'employee'
}}
])