How to fetch data from multiple collections in MongoDB using a single query. I have 4 collections in which I want to fetch all active status records with limit 20
Below is my query sample
db.seasons.aggregate([
{ "$facet": {
"c1": [
{ "$lookup": {
"from": "episodes",
"pipeline": [
{ "$match": { "status": 1 } }
],
"as": "collection1"
}}
],
"c2": [
{ "$lookup": {
"from": "movies",
"pipeline": [
{ "$match": { "upcoming": 0 } }
],
"as": "collection2"
}}
],
"c3": [
{ "$lookup": {
"from": "shows",
"pipeline": [
{ "$match": { "upcoming": 0 } }
],
"as": "collection3"
}}
]
}},
{ "$project": {
"data": {
"$concatArrays": [ "$c1", "$c2", "$c3" ]
}
}},
{ "$unwind": "$data" },
{ "$replaceRoot": { "newRoot": "$data" } },
{ $limit : 20 },
{$sort: {"createdAt": -1}}
])
I am getting error as : MongoServerError[Location4568]: PlanExecutor error during aggregation :: caused by :: Total size of documents in episodes matching pipeline’s $lookup stage exceeds 104857600 bytes