2017-04-19 84 views
3

我正在编写邮件标签,并且需要为每个文档打印标签。C#MongoDB驱动程序仅返回100个结果

我在集合上有829个文档,但是当我检索它们时,我只能得到100个文档。

我有这样的LINQ代码:

IMongoCollection Pessoa; 
Pessoa = database.GetCollection<Pessoa>(collectionName); 

return Pessoa.AsQueryable().ToList(); 

如何检索所有的文件?

+0

return Pessoa.AsQueryable()。OrderBy(d => d.Nome).ToList();剧照仅检索100个文件。 – Tony

+1

也许你有一个'Limit'设置在任何地方? – Pikoh

+1

是否所有的对象在Nome属性中都有一个值? –

回答

1

我在集合上有829个文档,但是当我检索它们时,我只能得到100个文档。

我可以重现我这边的问题,使用上IMongoCollection collection.AsQueryable() AsQueryable已扩展方法来找到一个集合,它总是返回100个文件,即使我改变项目每页面设置为无限制在Azure门户网站中的文件。

设置:

enter image description here

测试代码:在查询浏览器

enter image description here

计数文件:

enter image description here

要查询正如您在评论中提到的,集合中的所有文档都可以尝试使用空滤镜调用Find method

+0

我测试并确认此默认行为返回100个文档也发生在非Microsoft服务器上,如Mongo Atlas。 – Tony

1

您可能受限于默认cursor BatchSize。 您可以修改此行为,将AggregateOptions对象传递给AsQueryable扩展名,并将BatchSize属性设置为足够大的值。

public static IMongoQueryable<TDocument> AsQueryable<TDocument>(this IMongoCollection<TDocument> collection, AggregateOptions aggregateOptions = null)