sh.splitAt()

On this page本页内容

Definition定义

sh.splitAt(namespace, query)

Splits a chunk at the shard key value specified by the query.在查询指定的分片键值处拆分块。

The method takes the following arguments:该方法采用以下参数:

Parameter参数Type类型Description描述
namespacestringThe namespace (i.e. <database>.<collection>) of the sharded collection that contains the chunk to split.包含要拆分的区块的分片集合的命名空间(即<database>.<collection>)。
querydocumentA query document that specifies the shard key value at which to split the chunk. 一个查询文档,指定分割块的分片键值。

The sh.splitAt() method wraps the split command.sh.splitAt()方法包装了split命令。

Consideration注意事项

In most circumstances, you should leave chunk splitting to the automated processes within MongoDB. 在大多数情况下,应该将区块分割留给MongoDB中的自动化进程。However, when initially deploying a sharded cluster, it may be beneficial to pre-split manually an empty collection using methods such as sh.splitAt().但是,在最初部署分片集群时,使用sh.splitAt()等方法手动预拆分空集合可能会有所帮助。

Behavior行为

sh.splitAt() splits the original chunk into two chunks. 将原始块拆分为两个块。One chunk has a shard key range that starts with the original lower bound (inclusive) and ends at the specified shard key value (exclusive). 一个块具有一个分片键范围,该范围以原始下限(包含)开始,以指定的分片键值(不包含)结束。The other chunk has a shard key range that starts with the specified shard key value (inclusive) as the lower bound and ends at the original upper bound (exclusive).另一个块具有一个分片键值范围,该范围以指定的分片键值(包括)作为下限开始,以原始上限(不包括)结束。

To split a chunk at its median point instead, see sh.splitFind().要改为在块的中间点拆分块,请参阅sh.splitFind()

Example示例

For the sharded collection test.foo, the following example splits a chunk at the shard key value x: 70.对于分片集合test.foo,以下示例在分片键值x:70处拆分块。

sh.splitAt( "test.foo", { x: 70 } )
←  sh.shardCollection()sh.splitFind() →