Hi.
I working on mongodb database with a collection contains 12 million record of users payments.
scheme of document in this collection :
{
"_id": ObjectId(),
"amount": 0,
"sharing_plan": 30,
"start_time": 0,
"end_time": 0,
"pay_code": "",
"user_id": "",
"date" : {
"year" : "2021",
"month" : "01",
"day" : "01"
}
}
I have to analyze this data annually, monthly and daily (for example, how much we earned in each month of the year).
I have to use $ group here.
But it is very slow and takes up to 15 seconds.
my aggregation :
database.collection("payments").aggregate([
{
$match: {
$and: [
{
"date.year": "2021"
},
{
"date.month": "01"
}
]
}
},
{
$group: {
"_id": "$date.month",
"sumAmount": {"$sum": "$amount"}
}
},
{
$project: {
"_id": 0,
"month": "$_id",
"sumAmount": "$sumAmount"
}
}
])
how to speed up this process ??
please help.