Additional Overhead
Each index occupies a certain amount of storage space, and the indexes need to be manipulated when inserting, updating, and deleting operations. Therefore, if you seldom read the collection, we recommend that you do not use the index.
Memory (RAM) usage
Because the index is stored in memory (RAM), you should ensure that the size of the index does not exceed the memory limit.
If the size of the index is greater than the memory limit, MongoDB will delete some indexes, which will result in degraded performance.
Query limits
The index cannot be used by the following query:
- Regular expressions and non-operators, such as $nin, $not, and so on.
- Arithmetic operators, such as $mod, and so on.
- $where clauses
Therefore, it is a good habit to detect whether your statements use indexes, which can be viewed with explain.
Index key limit
Starting with version 2.6, if the value of an existing indexed field exceeds the index key limit, the index is not created in MongoDB.
Insert document exceeds index key limit
If the index field value of the document exceeds the limit of the index key, MongoDB does not convert any documents into indexed collections. Similar to the Mongorestore and Mongoimport tools.
Maximum Range
- Cannot have more than 64 indexes in a collection
- Index name cannot exceed 125 characters in length
- A composite index can have a maximum of 31 fields
MongoDB Index Limit