'Mongo Aggregation passing from sqlite database to mongo

I'm migrating a desktop application to api rest service, the original application worked with a sqlite data base and the new rest api service will work with mongo

I have these three tables:

enter image description here

I know that if i'm working with mongo the best way to make this is puting the activities inside role document like this:

{
  _id: "123",
  description: "Some role",
  activities:[
    {"description": "Activity1"},
    {"description": "Activity2"},
  ]
}

But is mandatory that I keep exactly the same data base structure so I have the same three tables in mongo

I'm trying to make a aggregation to get a object like this passing as parameter a roleid this is the aggregation that i have:

[{$lookup: {
 from: 'RolItems',
 localField: 'idRol',
 foreignField: '_id',
 as: 'rol'
}}, {$unwind: {
 path: '$rol'
}}, {$lookup: {
 from: 'ActivityItems',
 localField: 'idActivity',
 foreignField: '_id',
 as: 'activity'
}}, {$unwind: {
 path: '$activity'
}}, {$project: {
 idRol: '$idRol',
 description: '$rol.description',
 activity: '$activity.description',
 idActivity: '$_id'
}}]

But the result of this is:

{
  _id:Binary('d6dOGW6ZQkGLvOdqqPl4VQ==', 3)
  idRol:Binary('+UvcOIa2x0CND1zDoleZpg==', 3)
  description:"Admin Impresión"
  activity:"Adminisración de contenedores"
  idActivity:Binary('d6dOGW6ZQkGLvOdqqPl4VQ==', 3)
}

How could i make a aggregation that give me as result this object?

{
  _id: "123",
  description: "Some role",
  activities:[
    {"description": "Activity1"},
    {"description": "Activity2"},
  ]
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source