English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Index Limit in MongoDB

In this chapter, we will learn about index limitations and their other components.

Additional overhead

Each index consumes some space and incurs overhead during each insertion, update, and deletion. Therefore, if you rarely use the collection for read operations, it is best not to use indexes.

RAM usage

Since indexes are stored in RAM, ensure that the total size of the indexes does not exceed the RAM limit. If the total size exceeds the RAM size, it will start deleting some indexes, resulting in performance degradation.

query restrictions

indexes cannot be used for queries that-

  • regular expressions or negation operators, such as $nin, $not, etc.

  • arithmetic operators, such as $mod, etc.

  • $where clause

Therefore, it is always recommended to check the index usage of the query.

index key limit

From2.6From version, if the value of the existing index field exceeds the index key limit, MongoDB will not create the index.

Insert file exceeds index key limit

If the index field value of this document exceeds the index key limit, MongoDB will not insert any document into the indexed collection. The mongorestore and mongoimport utilities are the same as well.

maximum range

  • a collection cannot have more than64indices.

  • the length of the index name cannot exceed125characters.

  • a compound index can have at most31a field is indexed.