Skip to content

i3arnon/MongoAsyncEnumerableAdapter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Provides an adapter from MongoDB's IAsyncCursor & IAsyncCursorSource to IAsyncEnumerable

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages