Reputation: 177
I'm using the 10gen c# MongoDB driver from mongodb.org and I'm attempting to get all the rows from a collection that has 2 Million+ rows. Here is the code:
var mongoServer = dataHelper.GetMongoServer();
var mongoDatabase = mongoServer.GetDatabase("MyDB");
var mongoCollection = mongoDatabase.GetCollection<MyClass>("MyClass");
var mongoCount = mongoCollection.Count();
var mongoCursor = mongoCollection.FindAll();
mongoCursor.SetBatchSize(1000);
var totalCount = 0;
foreach(var myClass in mongoCursor)
{
++totalCount;
//process record
}
When the foreach statement is complete totalCount is only about 91% of the mongoCount the collection has in it. Is there something wrong with my code?
Upvotes: 1
Views: 2807
Reputation: 53685
1 Mb yous issue because of you changed Batch Size? Because the default batch size is actually 4mb. Try without set batch size.
2 Did you tried to set limit directly for example to 3 millions?
3 Also did you tried to get data in parts, for example by half of million, because mb some timeout at mongodb or at the driver?
4 About cuncurrency at mongo db.
Hope this help.
Upvotes: 1