Sharding Reference

Sharding Methods in the mongo Shell

NameDescription
sh.addShard()Adds a shard to a sharded cluster.
sh.addShardTag()In MongoDB 3.4, this method aliases to sh.addShardToZone().
sh.addShardToZone()Associates a shard to a zone. Supports configuring zones in sharded clusters.
sh.addTagRange()In MongoDB 3.4, this method aliases to sh.updateZoneKeyRange().
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.disableAutoSplit()Disables auto-splitting for the sharded cluster.
sh.enableAutoSplit()Enables auto-splitting for the sharded cluster.
sh.enableSharding()Enables sharding on a specific database.
sh.getBalancerHost()Deprecated since MongoDB 3.4
sh.getBalancerState()Returns a boolean to report if the balancer is currently enabled.
sh.removeTagRange()In MongoDB 3.4, this method aliases to sh.removeRangeFromZone().
sh.removeRangeFromZone()Removes an association between a range of shard keys and a zone. Supports configuring zones in sharded clusters.
sh.help()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()In MongoDB 3.4, this method aliases to sh.removeShardFromZone().
sh.removeShardFromZone()Removes the association between a shard and a zone. Use to manage zone sharding.
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.
sh.updateZoneKeyRange()Associates a range of shard keys to a zone. Supports configuring zones in sharded clusters.
convertShardKeyToHashed.txt()Returns the hashed value for the input.

Sharding Database Commands

The following database commands support sharded clusters.

NameDescription
addShardAdds a shard to a sharded cluster.
addShardToZoneAssociates a shard with a zone. Supports configuring zones in sharded clusters.
balancerStartStarts a balancer thread.
balancerStatusReturns information on the balancer status.
balancerStopStops the balancer thread.
checkShardingIndexInternal command that validates index on shard key.
cleanupOrphanedRemoves orphaned data with shard key values outside of the ranges of the chunks owned by a shard.
enableShardingEnables sharding on a specific database.
flushRouterConfigForces a mongod/mongos instance to update its cached routing metadata.
getShardMapInternal command that reports on the state of a sharded cluster.
getShardVersionInternal command that returns the config server version.
isdbgridVerifies that a process is a mongos.
listShardsReturns a list of configured shards.
medianKeyDeprecated internal command. See splitVector.
moveChunkInternal command that migrates chunks between shards.
movePrimaryReassigns the primary shard when removing a shard from a sharded cluster.
mergeChunksProvides the ability to combine chunks on a single shard.
removeShardStarts the process of removing a shard from a sharded cluster.
removeShardFromZoneRemoves the association between a shard and a zone. Supports configuring zones in sharded clusters.
setShardVersionInternal command to sets the config server version.
shardCollectionEnables the sharding functionality for a collection, allowing the collection to be sharded.
shardingStateReports whether the mongod is a member of a sharded cluster.
splitCreates a new chunk.
splitChunkInternal command to split chunk. Instead use the methods sh.splitFind() and sh.splitAt().
splitVectorInternal command that determines split points.
unsetShardingInternal command that affects connections between instances in a MongoDB deployment.
updateZoneKeyRangeAdds or removes the association between a range of sharded data and a zone. Supports configuring zones in sharded clusters.

Reference Documentation