[ad_1]
I have a query that return me something like that(I am also using Compass to see the results) :
[ { subscribers: [...] }, { subscribers: [...] }, ... ]
but what I want is to join al that “sub-arrays” called “subscribers” in one only array in an aggregation but I don’nt know how to do that. This is my code:
return this.subscriptions
.aggregate([
{
'$match': {
'entity': params.entity,
'status': 'active'
}
},
{
'$lookup': {
'from': 'appsubscriptionssubscribers',
'localField': '_id',
'foreignField': 'subscription',
'as': 'subscribers'
}
},
{
'$match': {
'subscribers.0': {
'$exists': true
}
}
},
{ $skip : batch.skip },
{ $limit : batch.size },
{
'$project': {
'_id': 0,
'subscribers': 1
}
}
])
.toArray();
}
What can I do to achieve that? Thank you in advance.
[ad_2]