0

I am trying to fix performance issue with mongodb and one of issue is that system read number of products in each category with every page load. Project uses C# and FluentMongo to access database. (and this wasn't my idea :)

Ideally, i want to get such categoryid : count of products as one request.

Each Product may belong to multiple Categories.

Code which I am trying to imporove is:

int count = _products.AsQueryable().Where(p => p.Categories.Any(c => c.Id == category.Id)).Count();

and it is executed hundred of times....

st78
  • 8,028
  • 11
  • 49
  • 68

1 Answers1

1

You are going to need to use map reduce to do this type of query. FluentMongo is able to do a little map/reduce automagically for you, but not at the level you are wanting. Check out the map/reduce MongoDB docs at http://www.mongodb.org/display/DOCS/MapReduce. If you still need help, there is a MongoDB user group to help out as well at https://groups.google.com/forum/#!forum/mongodb-user.

Craig Wilson
  • 12,174
  • 3
  • 41
  • 45