简体   繁体   中英

Why is the MongoCursor not returning all results from a MongoCollection?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM