MongoCursor<BsonDocument> mongoCursor =
mongoCollection.Find(Query.And(some query))
.SetFlags(QueryFlags.NoCursorTimeout)
.SetFields(idFieldName);
int totalCount = 0;
Queue<List<long>> idBatchQueue = new Queue<List<long>>();
List<long> idBatch = new List<long>(batchSize);
foreach (BsonDocument document in mongoCursor)
{
idBatch.Add(document[idFieldName].ToInt64());
if (idBatch.Count >= batchSize)
{
idBatchQueue.Enqueue(idBatch);
totalCount += idBatch.Count;
idBatch = new List<long>(batchSize);
}
}
Firstly i was facing Command getMore failed: Cursor not found, cursor id:xxx error so for that i have added flag QueryFlags.NoCursorTimeout
.
But now i am facing Command getMore failed: End of file in foreach
loop of mongoCursor
.