MongoDB indexing restrictions
Each index occupies some storage space, during insert, update, and also need to delete the index operation. So, if you rarely read the collection, it is recommended not to use the index.
Memory (RAM) used
Since the index is stored in memory (RAM), you should make sure to limit the size of the index does not exceed the memory.
If the size of the index is greater than the memory limitations, MongoDB will remove some of the index, which will lead to performance degradation.
Index can not be use the following query:
- Regular expressions and non-operators, such as $ nin, $ not, and so on.
- Arithmetic operators, such as $ mod, and so on.
- $ Where clause
So, check your statement whether the index is a good habit, can explain to view.
Index key limit
From version 2.6, if the value of the existing index key index field exceeds the limit, MongoDB will not create the index.
Key index into the document exceeds limit
If the index field value of a document exceeds the limit of the index key, MongoDB does not convert any document into a collection index. Similar mongorestore and mongoimport tools.
- The index set not more than 64
- The length of the index name can not exceed 125 characters
- A composite index can have up to 31 fields