Hi - I'm noticing extremely slow loading MongoDB query in Retool that is instant when I run in MongoDB Compass.
return (async () => {
if(isLoggedInState) {
//console.log("LoggedIn is true");
var assignedTerritories = await MDBAssignmentsAggregateAssigned.trigger();
// If more than 4 territories, disable request button
if(assignedTerritories && _.keys(assignedTerritories).length > 0) {
if(assignedTerritories.length > 3) {
buttonRequestTerritory.setDisabled(true);
}
//console.log("assignedTerritories: "+assignedTerritories);
//console.log("selectedTerritory: "+selectAssignmentCurrent.value);
if(selectAssignmentCurrent.value === null || selectAssignmentCurrent.value === "") {
await selectAssignmentCurrent.setValue(assignedTerritories[0]._id.toString());
await currentAssignmentIDState.setValue(assignedTerritories[0]._id.toString());
await currentTerritoryIDState.setValue(assignedTerritories[0].No._id.toString());
}
if(selectAssignmentCurrent.value) {
await currentAssignmentIDState.setValue(selectAssignmentCurrent.value);
if(currentAssignmentIDState.value.length > 1) {
//console.log("currentAssignmentID: "+currentAssignmentIDState.value);
var currentAssignment = await MDBAssignmentsFindOne.trigger();
if(currentAssignment) {
await currentTerritoryIDState.setValue(currentAssignment.No.toString());
//console.log("currentTerritory: "+currentTerritoryIDState.value);
// If territory found, get addresses
if(currentTerritoryIDState.value.length > 0 ) {
var Addresses = await MDBTerritoriesAggregateAddresses.trigger();
if(Addresses) {
tableAddressesCurrentTerritory.selectRow(0);
GetTerritoryAddressCoordinatesforMap.trigger();
}
return true;
}
} else {
utils.showNotification({ title: "There was an error.", description: "We are unable to look up your assigned territories. Please contact support.", notificationType: "error", duration: 6 });
return false;
}
}
}
// Else if no selected territory
} else {
utils.showNotification({ title: "Please Request a Territory", description: "You have no territories. Please click \"Request Territory\" to check out a territory. If you have already done so, please wait for your territory to be assigned.", notificationType: "warning", duration: 6 });
return false;
}
}
})();