Reputation: 229
Hi I am having trouble keeping connection with my MongoDB and it ends up interrupting my program when it loses connection, how would I go about continuing to print from the last place that I lost connection at, I keep a count of the index but how do I use that count to start from that position in the cursor
using (server.RequestStart(db))
{
var cursor = col.FindAll();
foreach (var item in cursor)
{
//code here
}
}
Upvotes: 2
Views: 457
Reputation: 12187
Why are you having trouble keeping your connection to MongoDB open? Are you losing your network connection in the middle of the query? Are you timing out?
In general the only way to reliably restart a query is if the results are sorted and you use a query on the restart to skip over documents you already processed (in other words, skip over those documents where the sort key is less than or equal to the last document processed).
You probably don't need to call RequestStart. The only time you ever need to call RequestStart is if you want to ensure that a sequence of database operations all occur on the same connection (which is only needed in unusual circumstances).
Upvotes: 1