I have code like this where I want to query to MongoDB using Linq.
I get an AsQueryable from MongoDB collection.
public IEnumerable<IVideo> GetVideos()
{
    var collection = database.GetCollection<IVideo>("Videos");
    return collection.AsQueryable();
}
I call it like so,
var finalList = Filter2(Filter1(GetVideos())).Skip(2).Take(30);
foreach(var v in finalList)
{
    .... 
}
Functions with the queries.
public IEnumerable<IVideo> Filter1(IEnumerable<IVideo> list)
{
    return list.Where(q=>q.Categorized)
}
public IEnumerable<IVideo> Filter2(IEnumerable<IVideo> list)
{
    var query = from d in list
        where d.File == "string1" || d.File == "string2" 
                select d;
    return query;
}
My code works fine. I have my code hosted in an IIS and have around 50,000 records and the queries are a bit complex than the example. My worker process spikes to 17% and takes a few seconds to execute when the foreach is called. This is a ridiculous high for such a low date amount.
I have a couple of questions.
- Is the query being executed by .net or MongoDB? If it is executed by MongoDB why is my worker process taking such a hit?
- What are the steps I can take to improve the execution time to render the query and reduce the server load.
Thanks
 
                        
You're downloading all entries client-side by accident
IEnumerablecauses the queryable to execute and return results. Change the filter methods to accept and returnIQueryable.EDIT:
The code you posted:
Does not compile.
Your code should look like this: