The shardCollection command
syntax for using a hash algorithm is shown in the following diagram:
Element
Description
Restrictions
database
The name of the database that contains the collection
that is distributed across database servers.
The database must exist.
collection
The name of the collection that is distributed
across database servers.
The collection must exist.
column
The shard key that is used to distribute data across
the database servers of a shard cluster.
The column must exist.
Composite shard keys are
not supported.
field
The shard key that is used to distribute data across
the database servers of a shard cluster.
The field must exist.
Composite shard keys are
not supported.
table
The name of the table that is distributed across
database servers.
The table must exist.
For optimal query performance, connect to the wire listener
and run the MongoDB ensureIndex command on the
shard key of each of a cluster's shard servers. The ensureIndex command
ensures that an index for the collection or table is created on the
shard server.
Results
The name of a shard-cluster definition that is created by
a shardCollection command that is run through the
wire listener is:
Example
The following command defines a
shard cluster that uses a hash algorithm on the shard key value year to
distribute data across multiple database servers.