MongoDB Index Limitations
Additional Overhead
Each index occupies a certain amount of storage space, and indexes also need to be operated on during insert, update, and delete operations. Therefore, if you rarely perform read operations on a collection, it is recommended not to use indexes.
Memory (RAM) Usage
Since indexes are stored in memory (RAM), you should ensure that the size of the indexes does not exceed the memory limit.
If the size of the indexes is greater than the memory limit, MongoDB will delete some indexes, which will lead to performance degradation.
Query Limitations
Indexes cannot be used by the following queries:
- Regular expressions and non-operators, such as $nin, $not, etc.
- Arithmetic operators, such as $mod, etc.
- $where clause
Therefore, it is a good habit to check whether your statements use indexes, and you can use explain to view it.
Index Key Limitations
Starting from version 2.6, if the value of an existing index field exceeds the index key limit, MongoDB will not create the index.
Inserting Documents Exceeding the Index Key Limit
If the index field value of a document exceeds the index key limit, MongoDB will not convert any documents into an indexed collection. This is similar to the mongorestore and mongoimport tools.
Maximum Limits
- The number of indexes in a collection cannot exceed 64.
- The length of an index name cannot exceed 128 characters.
- A compound index can have at most 31 fields.