High latency (delayed response) in mongoose as api is called consecutively over time

Hi Everyone,
I have a simple api using the mongoose find method, along with an _id filter:

Fee.find(
{
_id: feeDocId,
},
(err, fee) => {
if (fee[0] !== undefined) {
if (!err && fee[0] != “”) {
res.json(fee[0][“gstno”]);
}
}
}
)

The problem is that the response time of this api keeps on increasing exponentially with time (high latency).

API call Latency (response time)
First time 68ms
Third time 22.75 sec
Fifth time 55.18 sec
Seventh time 1.6 minutes
ninth time 2.3 minutes
fired at api 2022-05-11T12:45:03+05:30 {}
response at api{
  explainVersion: '1',
  queryPlanner: {
    namespace: 'myFirstDatabase.fee',
    indexFilterSet: false,
    parsedQuery: { _id: [Object] },
    maxIndexedOrSolutionsReached: false,
    maxIndexedAndSolutionsReached: false,
    maxScansToExplodeReached: false,
    winningPlan: { stage: 'IDHACK' },
    rejectedPlans: []
  },
  executionStats: {
    executionSuccess: true,
    nReturned: 1,
    executionTimeMillis: 1,
    totalKeysExamined: 1,
    totalDocsExamined: 1,
    executionStages: {
      stage: 'IDHACK',
      nReturned: 1,
      executionTimeMillisEstimate: 0,
      works: 2,
      advanced: 1,
      needTime: 0,
      needYield: 0,
      saveState: 0,
      restoreState: 0,
      isEOF: 1,
      keysExamined: 1,
      docsExamined: 1
    },
    allPlansExecution: []
  },
  command: {
    find: 'fee',
    filter: { _id: new ObjectId("623042ce5fc371ac74c9b371") },
    projection: {},
    '$db': 'myFirstDatabase'
  },
 
}
response at  api  2022-05-11T12:48:41+05:30
API took this much time 217829

Any ideas as to why the latency increases progressively? Thanks in advance…

Hi @ROSHAN_NAIR

It’s been a while since you posted this question. Have you found out what’s causing this?

Since your query is a simple find by _id, I wonder if the problem is not due to MongoDB (find by _id is highly optimized), but more to do with how the find() was called in your code?

If this is still an issue, could you post a small, self contained code that can reproduce this situation consistently, along with your MongoDB version and your Mongoose version?

Best regards
Kevin

Hi @ROSHAN_NAIR
Did you manage to find the solution. i am facing same issue.