I want to optimize the time of lookup query or find() for more than 1000 doc ,
I implemented this query to make join between 3 collection as shown bellow
let logs = await this.profileModel.aggregate([
{
$match: {
bindedClient: name,
},
},
{
$lookup: {
from: 'tpes',
localField: 'nameUser',
foreignField: 'merchantName',
as: 'tpesBySite',
},
},
{
$lookup: {
from: 'logs',
localField: 'tpesBySite.terminalId',
foreignField: 'terminalId',
as: 'logsByTpes',
},
},
{ $unwind: '$tpesBySite' },
{ $unwind: '$logsByTpes' },
{
$project: {
// bindedSuperAdmin: '$bindedSuperAdmin',
// bindedBanque: '$bindedBanque',
// bindedClient: '$bindedClient',
uniqueID: '$logsByTpes.uniqueID',
sn: '$logsByTpes.sn',
terminalId: '$logsByTpes.terminalId',
transactionAmount: '$logsByTpes.transactionAmount',
currencyCode: '$logsByTpes.currencyCode',
transactionDate: '$logsByTpes.transactionDate',
transactionTime: '$logsByTpes.transactionTime',
transactionType: '$logsByTpes.transactionType',
cardPAN_PCI: '$logsByTpes.cardPAN_PCI',
onlineRetrievalReferenceNumber:
'$logsByTpes.onlineRetrievalReferenceNumber',
outcome: '$logsByTpes.outcome',
encryptionKeyKCV: '$logsByTpes.encryptionKeyKCV',
transactionEncrypted: '$logsByTpes.transactionEncrypted',
},
},
]);
return logs;
It take more than 5 sec just for 100 docs it’s kinda weird what if I work with more than 1000 , I’m sure there is a solution for this problem ,
I think for pagination but I’m working with ng2-smart-table I didn’t know what can get the indexes of every pages it seems every think behind the scene which I can’t handle
PLEASE SOME ONE HELP ME I’M STUCK