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 takes up some space and incurs overhead each time it is inserted, updated, and deleted. 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, it should be ensured 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 constraints

index cannot be used for-

  • 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 value of the index field of this document exceeds the index key limit, MongoDB will not insert any document into the index collection. The mongorestore and mongoimport utilities are the same.

maximum range

  • a collection cannot have more than64indexes.

  • The length of the index name cannot exceed125characters.

  • The maximum number of composite indexes can be31a field is indexed.