Trying to do some aggregation on mongo for around 700K records but it is taking around 11 sec to execute and process.
My query looks like
db.getCollection('XYZ').aggregate([
{$match:{zmUserId:"ABC"}},
{$group:{_id:{rmuser:"$rmUserId"}, uniqueValues:{$addToSet:"$assignmentId"}} },
{$project:{_id:1,count:{$size:"$uniqueValues"}}}
])
my collection
{
"_id" : ObjectId("614b4305805d3a52e89db2ae"),
"status" : "CALL_ANSWERED",
"setupDuration" : 2,
"ringDuration" : 28,
"talkDuration" : 19,
"wrapDuration" : 8,
"callRecordingUrl" : "",
"isFirst" : false,
"counsellorId" : "9ac29fa9-896b",
"leadId" : "d25163cc-9380",
"userId" : "4.10256E+15",
"designation" : "CENTRE_HEAD",
"chUserId" : "nitin.tomar",
"rmUserId" : "dhaval.gor",
"zmUserId" : "yog.raj",
"leadPhone" : "7318184",
"assignedDate" : NumberLong(1632190287872),
"activityDate" : NumberLong(1632322293656),
"assignmentId" : "61493f500c649325d7167626",
"metadataId" : "61284ade338ba0a636ad5562",
"lastUpdatedDate" : ISODate("2021-09-22T14:51:48.459Z"),
"creationTime" : NumberLong(1632322308459),
"createdBy" : "LeadCallDetails",
"lastUpdated" : NumberLong(1632322308459),
"lastUpdatedBy" : "LeadCallDetails",
"entityState" : "ACTIVE"
}
It is indexed properly.
Can someone please help and tell me what I am doing wrong.