Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongodb c# library Async

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.

like image 375
Alvin Avatar asked Feb 18 '23 19:02

Alvin


2 Answers

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)

like image 50
D.Rosado Avatar answered Mar 06 '23 06:03

D.Rosado


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."

like image 31
WiredPrairie Avatar answered Mar 06 '23 07:03

WiredPrairie