C # MongoDB driver only returns 100 results

I am writing a mailing label and you need to print a label for each document.

I have 829 documents in the collection, but when I get them I only get 100 documents.

I have this LINQ code:

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

return Pessoa.AsQueryable().ToList();

      

How to get ALL documents?

+3


source to share


2 answers


I have 829 documents in the collection, but when I get them I only get 100 documents.

I could reproduce the issue on my side using the AsQueryable extension method on IMongoCollection collection.AsQueryable()

to find documents in the collection that always return 100 documents, even if I changed the Positions per page to Unlimited setting in the Azure portal.

Installation:

enter image description here

Test code:



enter image description here

Count documents in query explorer:

enter image description here

To query all documents in a collection, as you mentioned in the comment, you can try to call the Find method with an empty filter.

+1


source


You are probably limited by the default BatchSize cursor . You can change this behavior by passing an object AggregateOptions

to the extension AsQueryable

and setting the property BatchSize

to a high enough value.



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

      

+1


source







All Articles