Difference between Find and FindAsync Difference between Find and FindAsync mongodb mongodb

Difference between Find and FindAsync


The difference is in a syntax.Find and FindAsync both allows to build asynchronous query with the same performance, only

FindAsync returns cursor which doesn't load all documents at once and provides you interface to retrieve documents one by one from DB cursor. It's helpful in case when query result is huge.

Find provides you more simple syntax through method ToListAsync where it inside retrieves documents from cursor and returns all documents at once.


Imagine that you execute this code in a web request, with invoking find method the thread of the request will be frozen until the database return results it's a synchron call, if it's a long database operation that takes seconds to complete, you will have one of the threads available to serve web request doing nothing simply waiting that database return the results, and wasting valuable resources (the number of threads in thread pool is limited).

With FindAsync, the thread of your web request will be free while is waiting the database for returning the results, this means that during the database call this thread is free to attend an another web request. When the database returns the result then the code continue execution.

For long operations like read/writes from file system, database operations, comunicate with another services, it's a good idea to use async calls. Because while you are waiting for the results, the threads are available for serve another web request. This is more scalable.

Take a look to this microsoft article https://msdn.microsoft.com/en-us/magazine/dn802603.aspx.