I have a collection that looks like the following and i'm having troubles to perform a $lookup and return it the way it was at the beginning but with the populated fields:
i have made comments on the fields i want to populate which are (agent, missions.clients.client)
{
"title":"Tournée libre",
"agent":"5d811943d2a2100017667228", // needs to be populated
"missions":[
{
"_id":"5d8a075346f10d679ab4383e",
"title":"Journée 3",
"clients":[
{
"_id":"5d8a075346f10d679ab4383f",
"valid":true,
"client":"5d1bc39aa2af623b94363b33", // this needs to be populated
"visit_time":"2019-09-24T12:03:38.383Z"
},
{
"_id":"5d8a0dc446f10d679ab43888",
"valid":true,
"client":"5d8a0c8346f10d679ab43886",
"visit_time":"2019-09-24T12:34:23.210Z"
},
]
}
],
"created_at":"2019-09-24T12:08:51.928Z",
"__v":2
}
and here is how the result should be:
{
"title":"Tournée libre",
"agent": {firstname: 'something', lastname: 'something else'}
"missions":[
{
"_id":"5d8a075346f10d679ab4383e",
"title":"Journée 3",
"clients":[
{
"_id":"5d8a075346f10d679ab4383f",
"valid":true,
"client": {firstname: 'something', lastname: 'something else'},
"visit_time":"2019-09-24T12:03:38.383Z"
},
{
"_id":"5d8a0dc446f10d679ab43888",
"valid":true,
"client":{firstname: 'something', lastname: 'something else'},
"visit_time":"2019-09-24T12:34:23.210Z"
},
]
}
],
"created_at":"2019-09-24T12:08:51.928Z",
"__v":2
}