MongoAsyncEnumerableAdapter
MongoAsyncEnumerableAdapter copied to clipboard
Provides an adapter from MongoDB's IAsyncCursor & IAsyncCursorSource to IAsyncEnumerable
MongoAsyncEnumerableAdapter
Provides an adapter from MongoDB's IAsyncCursor<TDocument> and IAsyncCursorSource<TDocument> to IAsyncEnumerable<T>
This allows plugging MongoDB's custom async iterators into the async LINQ ecosystem by wrapping IAsyncCursorSource<TDocument> or IAsyncCursor<TDocument> in an IAsyncEnumerable<T> implementation.
For example, iterating on a find result with await foreach:
IMongoCollection<Hamster> collection = // ...
IFindFluent<Hamster, Hamster> findFluent = collection.Find(hamster => hamster.Name == "bar");
await foreach (var hamster in findFluent.ToAsyncEnumerable())
{
Console.WriteLine(hamster.Age);
}
Or any other async LINQ operator:
IMongoCollection<Hamster> collection = // ...
int groupCount =
await collection.AsQueryable().
ToAsyncEnumerable().
GroupBy(hamster => hamster.Age).
CountAsync();