I am investigating performance issues with a MongoDB cluster, whereby upgrading from the Legacy Drivers to the latest drivers caused a massive spike in the number of queries being issued to the Mongo cluster. I suspect that these might be related to certain queries that are materialized using the AsEnumerable() extension method rather than the ToList() MongoDB extension method.
We know that AsEnumerable from System.Collections.Generic will produce an iterator; grabbing a single object from the collection at a time, whereas ToList() will materialize all the data from the Queryable into a new List object.
But what is the effect of using the AsEnumerable extension method to materialize MongoDB data from the IMongoQuerable implementation? e.g:
IMongoCollection.AsQueryable().Where(x => x.Y = z).AsEnumerable()
I suspect that the result will be to cause multiple queries to be issued (possibly by utilizing a Cursor under-the-hood) which would explain why we are seeing the number of queries issued on our database server increase significantly. But I am speculating; I've not been able to find any code in the MongoDB .NET drivers related to AsEnumerable() and its inner workings. The extension method seems to fall back to the implementation in the .NET Framework.
Can anyone give any insight before we start converting hundreds of AsEnumberables to ToLists?