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?
source to share
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:
Test code:
Count documents in query explorer:
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.
source to share
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)
source to share