How to improve the performance on lookup & group Aggregation

Good morning all,

am using compass v1.36.0 . most of the time getting errors like “Operation exceeded the time limit. Please try increasing the maxTimeMS for the query in the expanded filter options.”

Actually I have three collection

StudenStaff collection

[
{
user_id'313031393137303000',
StudenInd:'Y',
client_Id:'LA0XDA',
clientName:'LA0XDA',
country_id'CRYVN',
country_name:'VIETNAM',
userClient_id'101908617',
user_status:'A',
geo:'ASEAN',
programName:'X',
site_id'W26872',
site_name:'VNXG02',
state_id'VN_REGION',
subprogram_name:'LAXSub',
supervisor_email:'minhn@gma.com',supervisor_id'101483574',
Teacher_IND:'N',
}]

in the studentstaff collection

  • List item
    we have more than 4laks records,
    student, teachers, and their respective site and client details
    along with we have user_status(A- active , I- inactive) details
    so we can group the student or teachers by client wise / site wise/ geo wise/ country wise and get the active student and teachers

AccessSettings Collection

{_id:"object_id(33353453534),
client_Id:'AA0VIIRP',
client_name:'AA0VIIRP',
geo:'NORTH_AMERICA',
country_Id:'CRYUS',
Country_Name:'US',
site_id:'834',
site_name:'USVIIO-00',
Status''A'}

in the AccessSettings collection, we have account with site details with active status details [ status-: A - mean Active clients under the site, status-I mean inactive client under the site…]
from the Access settings collection we can get all the active client and site details.

Attendance Collection

[
{_id'64071b221078082370f5c4e8',
attendance_date:'2023-03-07T00:00:00.000Z',
user_id'313031383337333000
'}

we can expect the minimum record count for this collection is more than 50lakhs per month.

relationship between the collections.:

AccessSettings.site_id = StudenStaff.stie_id && AccessSettings.client_id = StudenStaff.client_id
studentstaff.user_id = Attendance .userid

we need the output like below

{Date :
client_name  : 
geo     : 
country    : 
site      :
ActiveStudentCount   :
ActiveTeacherCount  :
StudentAttendanceCount  : 
TeacherAttendanceCount  :

Please help me to get the result from the above collections,
Actually I have tried with lookup and group aggregation maximum time getting the “Operation exceeded time limit.” error