0

When I return about 200,000 records to client the service works fine. But increasing the returned data(to 1 million) set causes below exception on server side:

System.InvalidOperationException: Server instance localhost:xxxx is no longer connected. 
at MongoDB.Driver.MongoServerInstance.AcquireConnection(MongoDatabase database) 
in C:\work\10gen\mongodb\mongo-csharp driver\Driver\Core\MongoServerInstance. cs:line 288

Somewhat happened when querying the database. I have the latest MongoDb driver. ConnectionPoolSize = 900 ConnectionTimeoutSeconds = 3000

Anatoly
  • 1,908
  • 4
  • 25
  • 47

1 Answers1

2

Read your data in smaller chunks/pages. See this question for more information:

MongoDB - paging

In short, you can do something like this:

int currentOffset = 0;
int recordsFetched;
do
{
    var results =
        collection.Find(query)
                  .SetSkip(currentOffset)
                  .SetLimit(100)
                  .ToList();

    currentOffset += 100;
    recordsFetched = results.Count;

    // Process your data here.
} while(recordsFetched > 0);
Community
  • 1
  • 1
Dmytro Shevchenko
  • 33,431
  • 6
  • 51
  • 67