Docs Menu
Docs Home
/
MongoDB Manual
/ / /

sh.splitAt()

On this page

  • Definition
  • Consideration
  • Behavior
  • Example
sh.splitAt(namespace, query)

Splits a chunk at the shard key value specified by the query.

Important

mongosh Method

This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.

For the database command, see the split command.

For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.

For the legacy mongo shell documentation, refer to the documentation for the corresponding MongoDB Server release:

mongo shell v4.4

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.

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

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

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 } )

Back

sh.shardCollection()