- Reference >
- MongoDB Limits and Thresholds
MongoDB Limits and Thresholds¶
This document provides a collection of hard and soft limitations of the MongoDB system.
- BSON Document Size¶
The maximum BSON document size is 16 megabytes.
The maximum document size helps ensure that a single document cannot use excessive amount of RAM or, during transmission, excessive amount of bandwidth. To store documents larger than the maximum size, MongoDB provides the GridFS API. See mongofiles and the documentation for your driver for more information about GridFS.
- Namespace Length¶
Each namespace, including database and collection name, must be shorter than 123 bytes.
- Number of Namespaces¶
The limitation on the number of namespaces is the size of the namespace file divided by 628.
A 16 megabyte namespace file can support approximately 24,000 namespaces. Each collection and index is a namespace.
- Size of Namespace File¶
Namespace files can be no larger than 2047 megabytes.
By default namespace files are 16 megabytes. You can configure the size using the nssize option.
- Index Key¶
The total size of an index key entry, which can include structural overhead depending on the BSON type, must be less than 1024 bytes.
Changed in version 2.6: MongoDB 2.6 implements a stronger enforcement of the limit on index key length:
MongoDB will not create an index on a collection if the value of the index field in an existing document exceeds the index key limit. Previous versions of MongoDB would create the index but not index such documents.
Reindexing operations will error if an indexed field exceeds the index key limit. Reindexing operations occur as part of compact and repairDatabase commands as well as the db.collection.reIndex() method.
Because these operations drop all the indexes from a collection and then recreate them sequentially, the error from the index key limit prevents these operations from rebuilding any remaining indexes for the collection and, in the case of the repairDatabase command, from continuing with the remainder of the process.
MongoDB will not insert into an indexed collection any document with an indexed field value that exceeds the index key limit, and instead, will return an error. Previous versions of MongoDB would insert but not index such documents.
Updates to the indexed field will error if the new value for the field exceeds the index key limit.
If an existing document contains a value for the indexed field that exceeds the limit, any update that results in the relocation of that document on disk will error.
In MongoDB 2.6, secondary members of replica sets will continue to replicate documents with an indexed field value that exceeds the index key limit on initial sync but will print warnings in the logs.
Secondary members also allow index build and rebuild operations on a collection that contains an indexed field value that exceeds the index key limit but with warnings in the logs.
With mixed version replica sets where the secondaries are version 2.6 and the primary is version 2.4, secondaries will replicate documents inserted or updated on the 2.4 primary, but will print error messages in the log if the documents contain indexed field value that exceeds the index key limit.
For existing sharded collections, chunk migration will fail if the chunk has a document that contains an indexed field value that exceeds the index key limit.
- Number of Indexes per Collection¶
A single collection can have no more than 64 indexes.
- Index Name Length¶
The names of indexes, including their namespace (i.e database and collection name), cannot be longer than 125 characters. The default index name is the concatenation of the field names and index directions.
You can explicitly specify an index name to the ensureIndex() helper if the default index name is too long.
- Number of Indexed Fields in a Compound Index¶
There can be no more than 31 fields in a compound index.
- Queries cannot use both text and Geospatial Indexes¶
You cannot combine the text command, which requires a special text index, with a query operator that requires a different type of special index. For example you cannot combine text command with the $near operator.
The unique indexes limit in Sharding Operational Restrictions.
- Maximum Number of Documents in a Capped Collection¶
Changed in version 2.4.
If you specify a maximum number of documents for a capped collection using the max parameter to create, the limit must be less than 232 documents. If you do not specify a maximum number of documents when creating a capped collection, there is no limit on the number of documents.
- Data Size¶
A single mongod instance cannot manage a data set that exceeds maximum virtual memory address space provided by the underlying operating system.
Virtual Memory Limitations Operating System Journaled Not Journaled Linux 64 terabytes 128 terabytes Windows 4 terabytes 8 terabytes
- Number of Collections in a Database¶
The maximum number of collections in a database is a function of the size of the namespace file and the number of indexes of collections in the database.
See Number of Namespaces for more information.
- Number of Members of a Replica Set¶
Replica sets can have no more than 12 members.
- Number of Voting Members of a Replica Set¶
Only 7 members of a replica set can have votes at any given time. See can vote Non-Voting Members for more information
- Sorted Documents¶
MongoDB will only return sorted results on fields without an index if the sort operation uses less than 32 megabytes of memory.
- Aggregation Pipeline Operation¶
Changed in version 2.6.
Pipeline stages have a limit of 100 megabytes of RAM. If a stage exceeds this limit, MongoDB will produce an error. To allow for the handling of large datasets, use the allowDiskUsage option to enable aggregation pipeline stages to write data to temporary files.
- 2d Geospatial queries cannot use the $or operator¶
- Spherical Polygons must fit within a hemisphere.¶
Any geometry specified with GeoJSON to $geoIntersects or $geoWithin queries, must fit within a single hemisphere. MongoDB interprets geometries larger than half of the sphere as queries for the smaller of the complementary geometries.
- Bulk Operation Size¶
A bulk operation can have at most 1000 operations.
- Database Name Case Sensitivity¶
Database names are case sensitive even if the underlying file system is case insensitive. MongoDB does not permit database names that differ only by the case of the characters.
- Restrictions on Database Names for Windows¶
Changed in version 2.2: Restrictions on Database Names for Windows.
For MongoDB deployments running on Windows, MongoDB will not permit database names that include any of the following characters:
Also, database names cannot contain the null character.
- Restrictions on Database Names for Unix and Linux Systems¶
For MongoDB deployments running on Unix and Linux systems, MongoDB will not permit database names that include any of the following characters:
Also, database names cannot contain the null character.
- Length of Database Names¶
Database names cannot be empty and must have fewer than 64 characters.
- Restriction on Collection Names¶
New in version 2.2.
Collection names should begin with an underscore or a letter character, and cannot:
- contain the $.
- be an empty string (e.g. "").
- contain the null character.
- begin with the system. prefix. (Reserved for internal use.)