- Your device is running a recent version of Linux, Windows or macOS
- Docker and Docker Compose are already installed on your device
- You'll need a MongoDB client in order to connect to the cluster (you may use the MongoDB Shell or MongoDB Compass)
- Launch a command line terminal (e.g. bash, zsh, cmd) and start the container for the configuration server:
docker compose up -d configsvr
- Connect to the configuration server from the MongoDB Shell:
mongosh mongodb://<Your IP Address>:10001
- Initialize the configuration server:
rs.initiate(
{
_id: "config_rs",
configsvr: true,
members: [
{_id: 0, host: "<Your IP Address>:10001"}
]
}
)
If you want to check if the initialization was successful, you can use:
rs.status()
Leave the mongosh session with:
exit
- Start the containers for the shards:
docker compose up -d mongodb1 mongodb2 mongodb3
- Connect to any of the shards:
mongosh mongodb://<Your IP Address>:20001
- Initialize the shards:
rs.initiate(
{
_id: "shard_rs",
members: [
{_id: 0, host: "<Your IP Address>:20001"},
{_id: 1, host: "<Your IP Address>:20002"},
{_id: 2, host: "<Your IP Address>:20003"}
]
}
)
Check if the initialization went well:
rs.status()
Leave the mongosh session with:
exit
- Start the container for the "MongoDB Shard Utility":
docker compose up -d mongos
- Connect to the router via mongosh:
mongosh mongodb://<Your IP Address>:30001
- Add the shards to the cluster:
sh.addShard("shard_rs/<Your IP Address>:20001,<Your IP Address>:20002,<Your IP Address>:20003")
Check if all shards were added:
rs.status()