C#MongoDB驱动程序仅返回100个结果

C#MongoDB驱动程序仅返回100个结果,c#,mongodb,linq,azure-cosmosdb,C#,Mongodb,Linq,Azure Cosmosdb,我正在写一个邮寄标签,需要为每个文档打印一个标签 我收集了829个文档,但是当我检索它们时,我只得到100个文档 我有这个LINQ代码: IMongoCollection Pessoa; Pessoa = database.GetCollection<Pessoa>(collectionName); return Pessoa.AsQueryable().ToList(); imongosa; Pessoa=database.GetCollection(collectionNam

我正在写一个邮寄标签,需要为每个文档打印一个标签

我收集了829个文档,但是当我检索它们时,我只得到100个文档

我有这个LINQ代码:

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

return Pessoa.AsQueryable().ToList();
imongosa;
Pessoa=database.GetCollection(collectionName);
返回Pessoa.AsQueryable().ToList();
如何检索所有文档

我收集了829个文档,但是当我检索它们时,我只得到100个文档

我可以通过在IMongoCollection
collection.AsQueryable()
上使用AsQueryable扩展方法来重现这个问题,以查找集合中的文档,即使我在Azure portal上将每页项设置更改为“无限制”,该集合始终会返回100个文档

设置:

测试代码:

计算查询资源管理器中的文档数:


要查询集合中的所有文档,如您在注释中所述,您可以尝试使用空筛选器进行调用。

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

public static IMongoQueryable<TDocument> AsQueryable<TDocument>(this IMongoCollection<TDocument> collection, AggregateOptions aggregateOptions = null)
公共静态IMongoQueryable AsQueryable(此IMongoCollection集合,AggregateOptions AggregateOptions=null)

我发现这个问题很有用,所以我写了一个方便的
IEnumerator

私有密封类MongoCollectionEnumerator:IEnumerator{
私人收藏(IMongoCollection);;
私有IAsyncursor _cursor;//外部枚举器
私有IEnumerator\u currentBatchEnumerator;//内部枚举器
公共MongoCollection枚举器(IMongoCollection集合){
_收集=收集;
InternalInit();
}
#区域接口实现
电流互感器{
得到{
返回_currentBatchEnumerator.Current;
}
}
对象IEnumerator.Current{
得到{
返回此AsTypeDiEnumerator.Current;
}
}
bool IEnumerator.MoveNext(){
if(_currentBatchEnumerator!=null){
if(_currentBatchEnumerator.MoveNext()){
返回true;
}
}
//内部未初始化或已在末尾
if(_cursor.MoveNext()){
//通过递归将外部推进并向后推迟到内部
_currentBatchEnumerator=_cursor.Current.GetEnumerator();
返回ThisAsIEnumerator.MoveNext();
}
否则{//outer无法前进,这就是终点
返回false;
}
}
void IEnumerator.Reset(){
内部清理();
InternalInit();
}
#端区
#区域方法私有
//帮助器属性,以检索为此浇铸的显式接口
私有IEnumerator ThisAsIEnumerator=>this;
private IEnumerator ThisAsTypedIEnumerator=>this;
私有void InternalInit(){
var filterBuilder=新的FilterDefinitionBuilder();
_游标=_collection.Find(filterBuilder.Empty).ToCursor();
}
私有void InternalCleanUp(){
if(_currentBatchEnumerator!=null){
_currentBatchEnumerator.Reset();
_currentBatchEnumerator=null;
}
如果(_cursor!=null){
_cursor.Dispose();
_游标=空;
}
}
#端区
#区域IDisposable实现
private bool disposedValue=false;//用于检测冗余调用
私有无效内部处置(bool处置){
如果(!disposedValue){
如果(处置){
内部清理();
_集合=空;
}
disposedValue=true;
}
}
void IDisposable.Dispose()无效{
(真实的);
}
#端区
}

return Pessoa.AsQueryable().OrderBy(d=>d.Nome.ToList();stills仅检索100个文档。可能您在任何地方设置了
限制
?是否所有对象都在Nome属性中有值?是的,所有对象都已填充Nome属性。任何地方都没有设置限制。假设
Pessoa
是集合,
AsQueryable()
导致聚合框架调用。您能检查一下其中一个是否适合您吗?我测试并确认返回100个文档的默认行为也发生在非Microsoft服务器上,如Mongo Atlas。