public async IAsyncEnumerable <Entry> ReadAsync( FhirStorePageReaderOptions options, [EnumeratorCancellation] CancellationToken cancellationToken = default) { options ??= new FhirStorePageReaderOptions(); var filter = Builders <BsonDocument> .Filter.Empty; var totalRecords = await _collection.CountDocumentsAsync(filter, cancellationToken : cancellationToken) .ConfigureAwait(false); for (var offset = 0; offset < totalRecords; offset += options.PageSize) { var data = await _collection.Find(filter) .Sort(Builders <BsonDocument> .Sort.Ascending(Field.PRIMARYKEY)) .Skip(offset) .Limit(options.PageSize) .ToListAsync(cancellationToken: cancellationToken) .ConfigureAwait(false); foreach (var envelope in data) { yield return(envelope.ToEntry()); } } }
public async Task <IPageResult <Entry> > ReadAsync(FhirStorePageReaderOptions options) { options = options ?? new FhirStorePageReaderOptions(); var filter = Builders <BsonDocument> .Filter.Empty; var totalRecords = await _collection.CountDocumentsAsync(filter) .ConfigureAwait(false); return(new MongoCollectionPageResult <Entry>(_collection, filter, options.PageSize, totalRecords, document => document.ToEntry())); }