MongoDB 的使用限制和瓶頸

原文地址https://docs.mongodb.org/manual/reference/limits/


BSON文檔

BSON 文檔大小


    BSON 最大是16M

    限制BSON文檔大小的原因是:

        1.文檔內存佔用

        2.網絡傳輸時帶寬的佔用

        3.要存儲大文檔請使用GridFS


BSON 內嵌文檔的深度


    MongoDB 支持不超過100層級的嵌套格式 BSON 文檔.


命名空間


命名空間長度

    MongoDB 集合名稱的最大長度不超過120字節

    文檔名稱 = 數據庫名 + 集合名 + 每個名稱的分隔符(分隔符是‘.’)


命名空間的數量

Changed in version 3.0.


    對 MMAPv1 來說命名空間的數量受限於命名空間文件的大小除以628。一個16M大小的命名空間文件可以支持接近24000個命名空間。每個集合和索引都佔一個命名空間。WiredTiger 存儲引擎不受這個限制。

命名空間文件大小

Changed in version 3.0.


對 MMAPv1儲存引擎來說, 命名空間文件的大小不能超過2047M。默認的命名空間文件大小是16M。

可以通過 選項 nsSize 來設置。WiredTiger 存儲引擎不受這個限制。


索引


索引長度

一個索引條目大小必須小於1024 字節.


單個集合的索引個數限制

    單個集合不能超過64個索引。


索引名稱長度

    全限定的索引名稱 (i.e. <database name>.<collection name>.$<index name>), 不能超過128個字符。


組合索引包含字段個數限制

    一個組合索引不能超過31個字段


查詢不能同時使用文本索引和地理空間索引


多鍵索引

    一個多鍵索引不支持 covered 查詢。


數據


有上限集合的最大文檔數

Changed in version 2.4.

    在創建一個有文檔數目上限的集合時如果不指定參數max, 則該集合沒有文檔數目限制。如果指定max參數則不能超過2的32次方。


數據庫大小

     MMAPv1 存儲引擎限制每個數據庫不能超過16000 個數據文件. 這意味着單個 MMAPv1 引擎的數據庫的數據不能超過32TB。 設置參數 storage.mmapv1.smallFiles 可以減小這個xian值到 8TB。


數據大小

Changed in version 3.0.


    使用 MMAPv1 存儲引擎, 單個mongod 實例管理的數據集不能超過操作系統提供的虛擬內存的最大空間。

    

Virtual Memory Limitations
操作系統JournaledNot Journaled
linxu
64T
128T
Windows Server 2012 R2 and Windows 8.164T128T
Windows othre4T8T

WiredTiger 存儲引擎沒有這個限制。


數據庫中集合數據限制


Changed in version 3.0.


對 MMAPv1存儲引擎來說。 一個數據庫中集合數目的限制取決於命名空間文件的大小和該數據庫中所有集合索引的數目.


WiredTiger 存儲引擎沒有這個限制。


複製集


複製集中成員數目的限制

Changed in version 3.0.0.

    複製集中成員個數不能超過50個


複製集中可以投票成員數目限制


    一個複製集中參與投票的成員不能超過7個。


自動創建的Oplog 集合大小

Changed in version 2.6.

    如果你沒有指定oplog的大小oplogSizeMB 或者 --oplogSize。MongoDB將自動創建一個大小不超過50G的opLog集合。


分片集羣


分片集羣操作限制


    一些操作在分片集羣環境下是不可用的可以通過mapReduce 或者聚合替代。


    db.eval()操作多分片後的集合是不適用的。你可以對分片集羣中一個不分片的集合使用 db.eval()操作。


$where does not permit references to the db object from the $where function. This is uncommon in un-sharded collections.


The $isolated update modifier does not work in sharded environments.


$snapshot queries do not work in sharded environments.


The geoSearch command is not supported in sharded environments.


Covered Queries in Sharded Clusters

An index cannot cover a query on a sharded collection when run against a mongos if the index does not contain the shard key, with the following exception for the _id index: If a query on a sharded collection only specifies a condition on the _id field and returns only the _id field, the _id index can cover the query when run against a mongos even if the _id field is not the shard key.


Changed in version 3.0: In previous versions, an index cannot cover a query on a sharded collection when run against a mongos.


對已經存在的集合進去切片

    對已經含有數據的集合如果集合大小不超過256G則MongoDB支持對該集合進去分片。 MongoDB 可能支持對不超過400G的集合進行分片這依賴於文檔的分佈情況。具體可以參考下表。

Shard Key Size 512 bytes200 bytes
Number of Splits31,55885,196
Max Collection Size (1 MB Chunk Size)31 GB83 GB
Max Collection Size (64 MB Chunk Size)1.9 TB5.3 TB

The data in this chart reflects documents with no data other than the shard key values and therefore represents the smallest possible data size that could reach this limit.


重點

    成功啓用分片後的集合大小是不固定的。

    分片集合中單個文檔修改操作限制

    一個啓用分片的集合的所有的修改和刪除操作 that specify the justOne or multi: false option must include the shard key or the _id field in the query specification. update() and remove() operations specifying justOne or multi: false in a sharded collection without the shard key or the _id field return an error.


分片集合中唯一索引限制

MongoDB does not support unique indexes across shards, except when the unique index contains the full shard key as a prefix of the index. In these situations MongoDB will enforce uniqueness across the full key, not a single field.


SEE

Enforce Unique Keys for Sharded Collections for an alternate approach.

Maximum Number of Documents Per Chunk to Migrate

MongoDB cannot move a chunk if the number of documents in the chunk exceeds either 250000 documents or 1.3 times the number of average sized documents that the maximum chunk size can hold.


Shard Key Limitations

Shard Key Size

A shard key cannot exceed 512 bytes.


Shard Key Index Type

A shard key index can be an ascending index on the shard key, a compound index that start with the shard key and specify ascending order for the shard key, or a hashed index.


A shard key index cannot be an index that specifies a multikey index, a text index or a geospatial index on the shard key fields.


Shard Key is Immutable

You cannot change a shard key after sharding the collection. If you must change a shard key:


Dump all data from MongoDB into an external format.

Drop the original sharded collection.

Configure sharding using the new shard key.

Pre-split the shard key range to ensure initial even distribution.

Restore the dumped data into MongoDB.

Shard Key Value in a Document is Immutable

After you insert a document into a sharded collection, you cannot change the document’s value for the field or fields that comprise the shard key. The update() operation will not modify the value of a shard key in an existing document.


Monotonically Increasing Shard Keys Can Limit Insert Throughput

For clusters with high insert volumes, a shard keys with monotonically increasing and decreasing keys can affect insert throughput. If your shard key is the _id field, be aware that the default values of the _id fields are ObjectIds which have generally increasing values.


When inserting documents with monotonically increasing shard keys, all inserts belong to the same chunk on a single shard. The system will eventually divide the chunk range that receives all write operations and migrate its contents to distribute data more evenly. However, at any moment the cluster can direct insert operations only to a single shard, which creates an insert throughput bottleneck.


If the operations on the cluster are predominately read operations and updates, this limitation may not affect the cluster.


To avoid this constraint, use a hashed shard key or select a field that does not increase or decrease monotonically.


Changed in version 2.4: Hashed shard keys and hashed indexes store hashes of keys with ascending values.


Operations


Sort Operations

If MongoDB cannot use an index to get documents in the requested sort order, the combined size of all documents in the sort operation, plus a small overhead, must be less than 32 megabytes.


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 allowDiskUse option to enable aggregation pipeline stages to write data to temporary files.


SEE ALSO

$sort and Memory Restrictions and $group Operator and Memory.

2d Geospatial queries cannot use the $or operator

SEE

$or and 2d Index Internals.

Area of GeoJSON Polygons

For $geoIntersects or $geoWithin, if you specify a single-ringed polygon that has an area greater than a single hemisphere, include the custom MongoDB coordinate reference system in the $geometry expression; otherwise, $geoIntersects or $geoWithin queries for the complementary geometry. For all other GeoJSON polygons with areas greater than a hemisphere, $geoIntersects or $geoWithin queries for the complementary geometry.


Write Command Operation Limit Size

Write commands can accept no more than 1000 operations. The Bulk() operations in the mongo shell and comparable methods in the drivers do not have this limit.


Naming Restrictions


Database Name Case Sensitivity

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.)

In the mongo shell, use db.getCollection() to specify collection names that might interact with the shell or are not valid JavaScript.


Restrictions on Field Names

Field names cannot contain dots (i.e. .) or null characters, and they must not start with a dollar sign (i.e. $). See Dollar Sign Operator Escaping for an alternate approach.


←  


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章