Skip to content

Instantly share code, notes, and snippets.

@bmarini
Created August 25, 2011 01:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmarini/1169735 to your computer and use it in GitHub Desktop.
Save bmarini/1169735 to your computer and use it in GitHub Desktop.
Local Replica Set
mkdir ~/tmp_mongo_data1
mkdir ~/tmp_mongo_data2
mkdir ~/tmp_mongo_data3
# In separate terminals
mongod --dbpath ~/tmp_mongo_data1 --port 5000 --replSet ben
mongod --dbpath ~/tmp_mongo_data2 --port 5001 --replSet ben
mongod --dbpath ~/tmp_mongo_data3 --port 5002 --replSet ben
# Then setup replication in a 4th terminal
echo 'rs.initiate({ _id: "ben", members: [ { _id: 0, host: "localhost:5000" } ] })' | mongo localhost:5000
echo 'rs.add("localhost:5001")' | mongo localhost:5000
echo 'rs.add("localhost:5002")' | mongo localhost:5000
# Now you can connect to your replica set
mongo localhost:5000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment