c# - Difference between Find and FindAsync -


i writing very, simple query gets document collection according unique id. after frusteration (i new mongo , async / await programming model), figured out:

imongocollection<tmodel> collection = // ... findoptions<tmodel> options = new findoptions<tmodel> { limit = 1 }; iasynccursor<tmodel> task = await collection.findasync(x => x.id.equals(id), options); list<tmodel> list = await task.tolistasync(); tmodel result = list.firstordefault(); return result; 

it works, great! keep seeing references "find" method, , worked out:

imongocollection<tmodel> collection = // ... ifindfluent<tmodel, tmodel> findfluent = collection.find(x => x.id == id); findfluent = findfluent.limit(1); tmodel result = await findfluent.firstordefaultasync(); return result; 

as turns out, works, great!

i'm sure there's important reason have 2 different ways achieve these results. difference between these methodologies, , why should choose 1 on other?

the difference in syntax. find , findasync both allows build asynchronous query same performance, only

findasync returns cursor doesn't load documents @ once , provides interface retrieve documents 1 one db cursor. it's helpful in case when query result huge.

find provides more simple syntax through method tolistasync inside retrieves documents cursor , returns documents @ once.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -