【发布时间】:2019-02-08 09:33:22
【问题描述】:
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);
}
}
首先我面临 Command getMore failed: Cursor not found, cursor id:xxx 错误,因此我添加了标志 QueryFlags.NoCursorTimeout。
但现在我面临foreachmongoCursor 循环中的Command getMore failed: End of file。
【问题讨论】:
-
感谢您的建议,但我已经阅读了本文档,它不是为了解决文件结尾问题。