I'm using Pymongo to run aggregate pipelines against our Mongodb.
I have the following collections:
users
{
_id: 1,
name: 'John Doe',
age: 30
},
{
_id: 2,
name: 'Jane Doe',
age: 20
}
locations
{
_id: 10,
name: 'Miami'
},
{
_id: 20,
name: 'Orlando'
}
contacts
{
_id: 100,
contacts: [
{
user_id: 1,
location_id: 10,
},
{
user_id: 2,
location_id: 20,
}
]
}
As result of an aggregate pipeline, I need:
{
_id: 100,
contacts: [
{
user_id: 1,
user_name: 'John Doe',
user_age: 30,
location_id: 10,
location_name: 'Miami'
},
{
user_id: 2,
user_name: 'Jane Doe',
user_age: 20,
location_id: 20,
location_name: 'Orlando'
}
]
}
I tried some queries using '$lookup', but I'm just getting a new array instead of putting the values inside the same array/object.
How can I get the desired result ?