Indexes for MongoDb for filtering request (various fields)

Hello everyone,

Was wondering if any of you had quite advanced knowledge on how to increase the speed of the mongodb request. I have watched the great video from @joshowens (https://www.youtube.com/watch?v=z9-9PCaEpbU) which explains clearly how indexes work for simple request (one or two field, one filter…) but my problematic is different but I guess far from unique.

I have a collection of products of around 7000 entries. These products have all similar data (color, size, weight, description, name, price, category…) and I have a filtering system that can allow you any type of custom search:

e.g:

  • size more than 10 but weight less than 5 and description should include “wood” and “table” (using $and request).
  • other search will be hardwood = true and price less than 1000 en description includes “tropical”

On top of this you have basic sorting by name or price, ascending, descending, etc… So my request can have from 1 simple field to more than 10 of them combined and sorting capacities.

I guess you can see where I am going : how to manage indexes to increase the speed of request ? I know we can do more bad than good with indexes so even though I am doing some tries with robomongo I still always get COLLSCAN and requests which I think could be faster.

Any help or guidance is welcome.

Thanks !

7000 documents are nothing for MongoDB.

Even if you create an index for each field, it should be ok.

So I could just createIndex for each field one by one without compound indexes and it will make the requests faster ?

I know 7000 is not a lot of data, but I still think the request speed can be increased a bit with proper indexing.

Compound index works better in some cases, check Sort order and Prefixed sections in doc https://docs.mongodb.com/manual/core/index-compound/#sort-order

But Single Field Indexes should be enough for you.