0

I have a MongoDB collection with 17M records. It has many queries with sorting and other filters with operators like >, <, NOT, IN (basically other than equality operators).

As mongo suggests that index with sorting should follow a specific order( Equality, Sorting, Range), I think I might end up with many indexes that are very specific to each and every query. Which may lead to other problems of over-indexing.

Is there a better way to handle this use case in MongoDB.

Mudit bhaintwal
  • 528
  • 1
  • 7
  • 21
  • https://stackoverflow.com/questions/62263023/what-is-the-correct-way-to-index-in-mongodb-when-big-combination-of-fields-exist/62268015#62268015 – D. SM Jul 09 '20 at 08:48
  • Does this answer your question? [What is the correct way to Index in MongoDB when big combination of fields exist](https://stackoverflow.com/questions/62263023/what-is-the-correct-way-to-index-in-mongodb-when-big-combination-of-fields-exist) – D. SM Jul 09 '20 at 08:48
  • @D.SM- Thanks for the response. This partially solves the problem. I am having all queries with sort order which makes mongo not picking right index if perfect match index does not present and erroring out with in-memory sort limit of 32 MB. So I can't afford to have few popular and selective queries covered with indexes while leaving others erroring out. – Mudit bhaintwal Jul 09 '20 at 10:56
  • What is your desired end state? allowDiskUse exists to make those queries complete with more resource usage, or you can add indexes. – D. SM Jul 09 '20 at 15:26
  • You can also try index hints. – D. SM Jul 09 '20 at 15:26

0 Answers0