Mohamed Farrag
Mohamed Farrag

Reputation: 1692

QueryFailure flag was could not find cursor in cache

I got the following error while i was listing MyCollection all documents:

MongoDB.Driver.MongoQueryException: QueryFailure flag was could not find cursor in cache for id 5389104123286064734 over MyCollection (response was { "$err" : "could not find cursor in cache for id 5389104123286064734 over collection MyCollection", "code" : 16336 })

MyCollection holds about 24000 documents and I'm using MongoDB driver for C#

Note: I got this exception sometimes, I did the same action again and it respond properly!!

Could you please explain this error, what is the possible causes, how to avoid it ?

Much appreciated.

Upvotes: 1

Views: 2129

Answers (1)

Craig Wilson
Craig Wilson

Reputation: 12624

The error means the cursor doesn't exist on the server. This could be for a couple of reasons.

Background: mongodb uses cursors and a cursor id to keep track of where you are in your result set. It does not stream all documents for your query all at once, but rather it sends them in batches. After iterating a complete batch, the driver will send back an OP_GETMORE to get the next batch.

Possibles issues:

  1. You are taking over 10 minutes to iterate the results of a single batch. Cursors timeout after 10 minutes. Best way to solve this is to specify a smaller batch size, say 20 documents per batch.

  2. You are hitting mongos behind a load balancer that does not use ip affinity. If the load balancer recieves the OP_GETMORE request on a different connection than the original query, then it might send the OP_GETMORE to a different server.

Upvotes: 3

Related Questions