Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

MongoDB index limits


May 17, 2021 MongoDB


Table of contents


MongoDB index limits


Additional overhead

Each index takes up a certain amount of storage space and needs to be operated on when inserting, updating, and deleting operations. T herefore, if you rarely read collections, it is not recommended to use indexes.


Memory (RAM) usage

Because the index is stored in memory (RAM), you should make sure 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 removes some indexes, which results in performance decline.


Query restrictions

The index cannot be used by the following queries:

  • Regular expressions and non-operators, such as $nin, $not, and so on.
  • Arithmetic operators, such as $mod, and so on.
  • $where clause

Therefore, it is a good habit to detect whether your statements use indexes, which can be viewed using explain.


Index key limit

Starting with version 2.6, if the value of an existing index field exceeds the index key limit, no index will be created in MongoDB.


Inserting a document exceeds the index key limit

MongoDB does not convert any documents into a collection of indexes if the index field value of the document exceeds the index key limit. Similar to mongorestore and mongoimport tools.


Maximum range

  • There can be no more than 64 indexes in the collection
  • Index names cannot be longer than 125 characters
  • A composite index can have up to 31 fields