I am using ASP.net Web API and MongoDB to create a simple service.
I am using the official Mongodb C# library.
How can I make it Async? I think the official Mongodb C# library does not support Async.
Can I just make the controller Async but not the select statement?
Controller:
public IQueryable<Test> GetAllPlaces()
{
return _test.GetAllPlaces().AsQueryable();
}
Select from mongodb database:
public IEnumerable<Test> GetAllPlaces()
{
return _test.FindAll();
}
Thank you.
Bit old question, but a full async MongoDB driver for C# is coming up in Nov 2013:
https://jira.mongodb.org/browse/CSHARP-138
edit- As Eugene said, the driver is still under development. There are some experimental projects on Github, while we wait for the official one
https://github.com/rstam/mongo-async-csharp-driver https://github.com/andrebires/mongo-csharp-driver
02-Apr-2015 Update:
2.0 is out!: Nuget Link But be aware that async GridFS is not supported yet, you'll need to keep using the legacy package to work with it, until they release it, probably in version 2.1
(thanks paqogomez for the heads up)
While you could make it async, doing so won't provide you any real performance gains as the underlying library isn't Async. There's a lot more to it and is described well here. The general answer is "no."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With