MongoDB C# Driver 'Cursor not found'

人走茶凉 提交于 2019-12-10 04:20:51

问题


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?


回答1:


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




回答2:


Further clarifying JohnnyHK's answer, this is the syntax:

MongoCursor<BsonDocument> cursor = myCollection
                                   .Find(query)
                                   .SetSortOrder(SortBy.Ascending("TrackingNumber"))
                                   .SetFlags(QueryFlags.NoCursorTimeout);



回答3:


I'm using MongoDB.Driver version 2.4.4 and IFindFluent is not containing SetFlags method. using this instead:

cursor.Options.NoCursorTimeout = true;


来源:https://stackoverflow.com/questions/14053803/mongodb-c-sharp-driver-cursor-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!