On this page本页内容
$where
does not permit references to the 不允许从db
object from the $where
function. $where
函数引用db
对象。This is uncommon in un-sharded collections.这在未分片的集合中很少见。
The 分片环境中不支持geoSearch
command is not supported in sharded environments.geoSearch
命令。
All 对于指定updateOne()
and deleteOne()
operations for a sharded collection that specify the multi: false
or justOne
option must include the shard key or the _id
field in the query specification.multi:false
或justOne选项的分片集合,所有updateOne()
和deleteOne()
操作都必须在查询规范中包含分片键或_id
字段。
updateOne()
and deleteOne()
operations specifying multi: false
or justOne
in a sharded collection which do not contain either the shard key or the _id
field return an error.updateOne()
和deleteOne()
操作在不包含分片键或_id
字段的分片集合中指定multi:false
或justOne
,将返回错误。
To use 要对分片集合使用findOneAndUpdate()
with a sharded collection, your query filter must include an equality condition on the shard key to compare the key and value in either of these formats:findOneAndUpdate()
,查询筛选器必须在分片键上包含相等条件,以比较以下任一格式的键和值:
{ key: value } { key: { $eq: value } }
MongoDB does not support unique indexes across shards, except when the unique index contains the full shard key as a prefix of the index. MongoDB不支持跨分片的唯一索引,除非唯一索引包含完整的分片键作为索引的前缀。In these situations MongoDB will enforce uniqueness across the full key, not a single field.在这些情况下,MongoDB将在整个密钥而不是单个字段中强制唯一性。
Unique Constraints on Arbitrary Fields任意字段上的唯一约束 for an alternate approach.以备不时之需。
An existing collection can only be sharded if its size does not exceed specific limits. 只有当现有集合的大小不超过特定限制时,才能对其进行分片。These limits can be estimated based on the average size of all shard key values, and the configured chunk size.可以根据所有分片键值的平均大小和配置的块大小来估计这些限制。
These limits only apply for the initial sharding operation. 这些限制仅适用于初始分片操作。Sharded collections can grow to any size after successfully enabling sharding.成功启用分片后,分片集合可以增长到任何大小。
Use the following formulas to calculate the theoretical maximum collection size.使用以下公式计算理论最大集合大小。
maxSplits = 16777216 (bytes) / <average size of shard key values in bytes> maxCollectionSize (MB) = maxSplits * (chunkSize / 2)
If 如果maxCollectionSize
is less than or nearly equal to the target collection, increase the chunk size to ensure successful initial sharding. maxCollectionSize
小于或几乎等于目标集合,请增加区块大小以确保初始分片成功。If there is doubt as to whether the result of the calculation is too 'close' to the target collection size, it is likely better to increase the chunk size.如果怀疑计算结果是否过于“接近”目标集合大小,则最好增加区块大小。
After successful initial sharding, you can reduce the chunk size as needed. 在成功进行初始分片后,可以根据需要减小块大小。If you later reduce the chunk size, it may take time for all chunks to split to the new size. 如果以后减小块大小,则可能需要一些时间才能将所有块拆分为新大小。See Modify Chunk Size in a Sharded Cluster for instructions on modifying chunk size.有关修改区块大小的说明,请参阅修改分片集群中的区块大小。
This table illustrates the approximate maximum collection sizes using the formulas described above:此表使用上述公式说明了近似的最大集合大小:
512 bytes | 256 bytes | 128 bytes | 64 bytes | |
---|---|---|---|---|
32,768 | 65,536 | 131,072 | 262,144 | |
1 TB | 2 TB | 4 TB | 8 TB | |
2 TB | 4 TB | 8 TB | 16 TB | |
4 TB | 8 TB | 16 TB | 32 TB |