Cursor not found

Hi! I hope you can help me with this issue. I’ve been investigating the cursor not found issue that we’ve been encountering in our staging environment.

We have an API that returns a cursor not found issue starting at page 6 of the GET endpoint.

We also have 2 other apis that has the same implementation of the pagination, but does not have the issue.

We are using the following:

  • sharded mongo
  • enabled sticky sessions to mongos
  • node v8
  • mongoose 5.13.9
  • mongoDB v3.4.24

Please note that our lower environment has the same setup as our staging, but we don’t have this issue.

I’ve also tried replicating this issue by running the API in my local machine and connecting it to the staging database, but can’t replicate the problem.

I also noticed when the API’s pod is restarted, the problem goes away but when the pod is 1 day old, it goes back. I’ve tried this multiple times.

I’ve been looking at this ticket: but upgrading is not an option for us for now.

This is the query that seems to have the problem:

2021-11-16T09:38:19.259+0000 I COMMAND [conn19900] command reekoh.system-logs command: find { find: “system-logs”, filter: { $or: [ { account: “account-id” }, { account: “-System-” } ], type: { $ne: “Delete” } }, projection: { $sortKey: { $meta: “sortKey” } }, sort: { date: -1, _id: 1 }, limit: 125, shardVersion: [ Timestamp 1000|0, ObjectId(‘606a7ee012bf595aff09f264’) ] } planSummary: IXSCAN { account: 1 } cursorid:237264813551 keysExamined:41684 docsExamined:41682 hasSortStage:1 numYields:326 nreturned:101 reslen:68395 locks:{ Global: { acquireCount: { r: 654 } }, Database: { acquireCount: { r: 327 } }, Collection: { acquireCount: { r: 327 } } } protocol:op_command 157ms