Search code examples
mongodbmongodb-.net-driver

MongoDB C# Driver 'Cursor not found'


I have quite an intensive operation that has a MongoCursor run in a loop for a few hours (on a vb.net app running via the c# driver. I'm not too sure what causes it but I run into an exception after a while

Cursor not found

This could be because of a cursor timeout, perhaps? Is there a way I can stop it happening? If its a timeout issue how do I place a longer timeout?


Solution

  • You can disable the cursor's timeout in the C# driver by calling:

    cursor.SetFlags(QueryFlags.NoCursorTimeout);
    

    Otherwise it will be closed after 10 minutes of inactivity.

    Reference