MongoDB Index Limitations
Overhead
Each index occupies a certain amount of storage space and requires index operations during insert, update, and delete operations. Therefore, if you rarely perform read operations on the 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 index does not exceed the memory limit.
If the size of the index exceeds the memory limit, MongoDB will drop 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 practice to check if your statements are using indexes, which can be viewed using explain.
Index Key Limitations
Starting from version 2.6, MongoDB will not create an index if the existing index field values exceed the index key limit.
Inserting Documents Exceeding Index Key Limit
If the index field values of a document exceed the index key limit, MongoDB will not convert any documents into indexed collections. Similar to the mongorestore and mongoimport tools.
Maximum Limits
No more than 64 indexes per collection
Index names cannot exceed 128 characters
A compound index can have up to 31 fields