Navigation
This version of the documentation is archived and no longer supported.

sh.splitAt()

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
namespace string The namespace (i.e. <database>.<collection>) of the sharded collection that contains the chunk to split.
query document A query document that specifies the shard key value at which to split the chunk.

The sh.splitAt() method wraps the split command.

Consideration

In most circumstances, you should leave chunk splitting to the automated processes within 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().

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

Example

For the sharded collection test.foo, the following example splits a chunk at the shard key value x: 70.

sh.splitAt( "test.foo", { x: 70 } )