MongoDB - Indexing Limits

MongoDB - Indexing Limits

Additional overhead

Each index takes up some space and also incurs overhead for every insert, update and delete. So if you rarely use your collection for read operations, it makes sense not to use indexes.

RAM usage

Since indexes are stored in RAM, you should ensure that the total index size does not exceed the RAM limit. If the total size increases the size of the RAM, it will start dropping some indexes, resulting in poor performance.

Query limits

Indexing cannot be used in queries that use −

  • Regular expressions or negation operators like $nin, $not etc.
  • Arithmetic operators like $mod etc.
  • item $ where

Hence, it is always a good idea to check index usage for your queries.

Key index limits

As of version 2.6, MongoDB will not create an index if the value of an existing index field exceeds the index key limit.

Inserting Documents Exceeding Key Index Limit

MongoDB will not insert any documents into an indexed collection if the value of that document's indexed field exceeds the index key limit. The same is the case with mongorestore and mongoimport.