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

Sharding Reference

Sharding Methods in the mongo Shell

Name Description
sh.addShard() Adds a shard to a sharded cluster.
sh.addShardTag() Associates a shard with a tag, to support tag aware sharding.
sh.addTagRange() Associates range of shard keys with a shard tag, to support tag aware sharding.
sh.disableBalancing() Disable balancing on a single collection in a sharded database. Does not affect balancing of other collections in a sharded cluster.
sh.enableBalancing() Activates the sharded collection balancer process if previously disabled using sh.disableBalancing().
sh.enableSharding() Enables sharding on a specific database.
sh.getBalancerHost() Returns the name of a mongos that’s responsible for the balancer process.
sh.getBalancerState() Returns a boolean to report if the balancer is currently enabled. Returns help text for the sh methods.
sh.isBalancerRunning() Returns a boolean to report if the balancer process is currently migrating chunks.
sh.moveChunk() Migrates a chunk in a sharded cluster.
sh.removeShardTag() Removes the association between a shard and a shard tag.
sh.setBalancerState() Enables or disables the balancer which migrates chunks between shards.
sh.shardCollection() Enables sharding for a collection.
sh.splitAt() Divides an existing chunk into two chunks using a specific value of the shard key as the dividing point.
sh.splitFind() Divides an existing chunk that contains a document matching a query into two approximately equal chunks.
sh.startBalancer() Enables the balancer and waits for balancing to start.
sh.status() Reports on the status of a sharded cluster, as db.printShardingStatus().
sh.stopBalancer() Disables the balancer and waits for any in progress balancing rounds to complete.
sh.waitForBalancer() Internal. Waits for the balancer state to change.
sh.waitForBalancerOff() Internal. Waits until the balancer stops running.
sh.waitForPingChange() Internal. Waits for a change in ping state from one of the mongos in the sharded cluster.

Sharding Database Commands

The following database commands support sharded clusters.

Name Description
flushRouterConfig Forces an update to the cluster metadata cached by a mongos.
addShard Adds a shard to a sharded cluster.
cleanupOrphaned Removes orphaned data with shard key values outside of the ranges of the chunks owned by a shard.
checkShardingIndex Internal command that validates index on shard key.
enableSharding Enables sharding on a specific database.
listShards Returns a list of configured shards.
removeShard Starts the process of removing a shard from a sharded cluster.
getShardMap Internal command that reports on the state of a sharded cluster.
getShardVersion Internal command that returns the config server version.
mergeChunks Provides the ability to combine chunks on a single shard.
setShardVersion Internal command to sets the config server version.
shardCollection Enables the sharding functionality for a collection, allowing the collection to be sharded.
shardingState Reports whether the mongod is a member of a sharded cluster.
unsetSharding Internal command that affects connections between instances in a MongoDB deployment.
split Creates a new chunk.
splitChunk Internal command to split chunk. Instead use the methods sh.splitFind() and sh.splitAt().
splitVector Internal command that determines split points.
medianKey Deprecated internal command. See splitVector.
moveChunk Internal command that migrates chunks between shards.
movePrimary Reassigns the primary shard when removing a shard from a sharded cluster.
isdbgrid Verifies that a process is a mongos.

Reference Documentation

Config Database
Complete documentation of the content of the local database that MongoDB uses to store sharded cluster metadata.