Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

docker-compose mongodb replica - init replica

#!/bin/bash
    
    echo "Starting replica set initialize"
    until mongo --host mongodb1 --eval "print("waited for connection")"
    do
        sleep 2
    done
    echo "Connection finished"
    echo "Creating replica set"
    mongo --host mongodb1 <<EOF
    rs.initiate(
      {
        _id : 'rs0',
        members: [
          { _id : 0, host : "mongodb1:27017" },
          { _id : 1, host : "mongodb2:27017" },
          { _id : 2, host : "mongodb3:27017" }
        ]
      }
    )
    EOF
    echo "replica set created"
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #mongodb #replica #init #replica
ADD COMMENT
Topic
Name
8+7 =