The query below takes up to 10 seconds to aggregate data. I have around 10 million records in collection. I tried multiple approaches but nothing worked. Any ideas?
db.collection.aggregate([
{
$match: {
start: {
$gte: new Date(monthBefore),
$lte: new Date(today)
}
}
},
{
$group: {
_id: {
symbol: '$symbol'
},
unverifiedCount: {
$sum: {
$cond: {
if: { $eq: ['$isVerified', false] }, then: '$count', else: 0
}
}
},
verifiedCount: {
$sum: {
$cond: {
if: { $eq: ['$isVerified', true] }, then: '$count', else: 0
}
}
}
}
}, {
$sort: {
unverifiedCount: -1
}
}
])