Files
k42api/start-replica-set.sh
Rytek Digital Inc 0ad4903124 updates
2025-08-03 10:37:36 -03:00

27 lines
620 B
Bash
Executable File

#!/bin/bash
# Create data directories if they don't exist
mkdir -p ./data/rs0-0 ./data/rs0-1 ./data/rs0-2
# Start each mongod instance
mongod --config mongod-rs0.conf
mongod --config mongod-rs1.conf
mongod --config mongod-rs2.conf
# Wait for mongod instances to start
sleep 5
# Initialize the replica set
mongosh --eval '
rs.initiate({
_id: "rs0",
members: [
{ _id: 0, host: "localhost:27017" },
{ _id: 1, host: "localhost:27018" },
{ _id: 2, host: "localhost:27019" }
]
})'
echo "Replica set initialized on ports 27017-27019. Waiting for primary election..."
sleep 5
mongosh --eval 'rs.status()'