Skip to content

Latest commit

 

History

History
32 lines (24 loc) · 1.26 KB

README.md

File metadata and controls

32 lines (24 loc) · 1.26 KB

MongoAsyncEnumerableAdapter

NuGet NuGet license

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();