当我尝试从集合中检索数千个文档时,我一直有这个错误。
index was out of range. must be non-negative and less than the size of the collection. parameter : Index
这是我查询文档时的代码:
MongoCollection<Book> collection = PDatabase.GetCollection<Book>("books");
List<IProduct> products = new List<IProduct>();
var books = collection.Find(Query.GT("stock", 0)).SetFlags(QueryFlags.NoCursorTimeout);
foreach (var book in books)
{
try
{
products.Add(book);
}
catch (Exception ex) { Console.WriteLine(ex.Message); }
}
return products;
当我查看异常消息时,它说&#34;索引超出范围。必须是非负的且小于集合的大小。参数:索引&#34;