how can i make execution more faster, following query is taking 3.3 seconds to execute from 55,000 records, as per me the $elemMatch
is taking more time, without that condition it executes in milliseconds. please help me to find the way to make it more faster.
db.getCollection('collection').aggregate([{
"$match": {
"is_expired": false,
"is_completed": true,
"is_deleted": false,
"$and": [{
"$or": [{
"reported_abusive": {
"$ne": true
}
}, {
"created_by": ObjectId("5ac6123e385e6a58669d8b06")
}]
}]
}
}, {
"$sort": {
"time_frame.end_on": 1
}
}, {
"$lookup": {
"from": "dburst",
"localField": "_id",
"foreignField": "dbursts.t_id",
"as": "dburst"
}
}, {
"$lookup": {
"from": "sburst",
"localField": "_id",
"foreignField": "t_id",
"as": "sburst"
}
}, {
"$match": {
"$or": [{
"created_by": ObjectId("5ac6123e385e6a58669d8b06")
}, {
"sburst": {
"$elemMatch": {
"shared_with": {
"$elemMatch": {
"user_id": ObjectId("5ac6123e385e6a58669d8b06"),
"is_dbursted": false,
"is_deleted": false
}
}
}
}
}, {
"dburst": {
"$elemMatch": {
"user_id": ObjectId("5ac6123e385e6a58669d8b06")
}
}
}]
}
}, {
"$skip": 0
}, {
"$limit": 10
}])