I have this two collections:
employees : {_id: NumberInt(0), name:"Max",surname:"Power"}, ..
and
loggableUser:{_id: NumberInt(0), employee: NumberInt(1), ..},
Now I have to insert into the following query a field "fullName" containing "employee.name" + " " + "employee.surname". I tried this query:
db.loggableUser.aggregate([
{
'$lookup':
{
'from': 'employees',
'localField': 'employee',
'foreignField' : '_id',
'as': 'employee'
}
},
{ "$addFields":{
"$employee.fullName" : "$employee.name" + " " + "$employee.surname"}])
but it does not work. I know is a simple thing but I can't get it works. Thank you.