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:

ParameterTypeDescriptionnamespacestringThe namespace (i.e. <database>.<collection>) of the shardedcollection that contains the chunk to split.querydocumentA query document that specifies the shard key value at whichto split the chunk.

The sh.splitAt() method wraps the splitcommand.

Consideration

In most circumstances, you should leave chunk splitting to theautomated processes within MongoDB. However, when initially deploying asharded cluster, it may be beneficial to pre-split manually an empty collection using methods such assh.splitAt().

Behavior

sh.splitAt() splits the original chunk into two chunks. Onechunk has a shard key range that starts with the original lower bound(inclusive) and ends at the specified shard key value (exclusive). Theother chunk has a shard key range that starts with the specified shardkey value (inclusive) as the lower bound and ends at the original upperbound (exclusive).

To split a chunk at its median point instead, seesh.splitFind().

Example

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

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