Creating a shard cluster with MongoDB commands
You create a shard cluster by adding shard servers with the MongoDB shell command
sh.addShard
command or the db.runCommand
command
with the addShard
syntax.
Before you begin
Procedure
To create a shard cluster from the MongoDB shell:
- Run the
mongo
command to start the MongoDB shell. -
Run one of the following commands with the host name and port that is specified for the
HCL
OneDB™ server that you want to add. The
specified port must run the HCL
OneDB
network-based listener, for example the onsoctcp protocol.
-
Run the
sh.addShard
command. -
Run the
db.runCommand
with theaddShard
command syntax. You can include the fully qualified domain name of the server instead of the host name. You can specify multiple servers.
-
Run the
Results
g_
. For example, the default Enterprise Replication group name for a database server that is named
myserver is g_myserver.Examples
- Add a server to a shard cluster with addShard
- The following command adds the database server that is at port 9202 of
myhost2.hcl.com to a shard
cluster:
> sh.addShard("myhost2.hcl.com:9202")
- Add a server to a shard cluster with db.runCommand and addShard
- The following command adds the database server that is at port 9204 of
myhost4.hcl.com to a shard cluster.
> db.runCommand({"addShard":"myhost4.hcl.com:9204"})
- Add multiple servers to a shard cluster
- This example adds the database servers that are at port 9205 of myhost5.hcl.com,
port 9206 of myhost6.hcl.com, and port 9207 of
myhost7.hcl.com to a shard cluster.
> db.runCommand({"addShard":["myhost5.hcl.com:9205", "myhost6.hcl.com:9206","myhost7.hcl.com:9207"]})