I just aggregate collectionA(total 9k records) to collectionB ( total 10k records) like this but it takes more than 1-2 hours to finish
db.collectionB .aggregate( [
{
$match:{"ngayGDich":{$gt:new Date('2021-12-09T07:00'),$lte: new Date('2021-12-10T07:00')},
"loaiGDich":{"$eq":"204"}
}
},
{
$lookup:{
from: "collectionA",
localField : "maGDichTChieu",
foreignField: "maGDich",
as: "data102"
},
},
{
$unwind:"$data102"
},
{
$facet: {
"soLuong200": [
{$match:
{"data102.loaiGDich": {"$eq": "200"}},
},{
$count:"value"
}
],
"soLuong203": [
{$match:
{"data102.loaiGDich": {"$eq": "203"}},
},{
$count:"value"
}
],
"soLuong300": [
{$match:
{"data102.loaiGDich": {"$eq": "300"}},
},{
$count:"value"
}
],
"soLuong400": [
{$match:
{"data102.loaiGDich": {"$eq": "400"}},
},{
$count:"value"
}
],
}
},
])
- my db size about 300 MB
Can another way resolve this issue?