#!/bin/bash
echo "Waiting for nodes to be ready..."
sleep 5

echo "Starting Replica Set configuration..."

mongosh --host mongo-rs1:27017 -u admin -p testpass123 --authenticationDatabase admin <<EOF
rs.initiate({
  _id: "rs0",
  members: [
    { _id: 0, host: "mongo-rs1:27017", priority: 2 },
    { _id: 1, host: "mongo-rs2:27017", priority: 1 },
    { _id: 2, host: "mongo-rs3:27017", priority: 1 }
  ]
});
EOF

echo "Waiting for Replica Set to be ready..."
sleep 10

mongosh --host mongo-rs1:27017 -u admin -p testpass123 --authenticationDatabase admin <<EOF
rs.status();
EOF

echo "✅ Replica Set configured successfully"
