- Reference >
mongo
Shell Methods >- Sharding Methods >
- sh.splitAt()
sh.splitAt()¶
On this page
Definition¶
-
sh.
splitAt
(namespace, query)¶ Splits a chunk at the shard key value specified by the query.
Important
mongo
Shell MethodThis page documents a
mongo
method. This is not the documentation for database commands or language-specific drivers, such as Node.js. To use the database command, see thesplit
command.For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.
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.
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
.