Skip to content

Instantly share code, notes, and snippets.

@autoize
Created May 24, 2020 18:04
Show Gist options
  • Save autoize/bb3ebc7389b248c9c8cffa08326d99a6 to your computer and use it in GitHub Desktop.
Save autoize/bb3ebc7389b248c9c8cffa08326d99a6 to your computer and use it in GitHub Desktop.
mongo_setup.sh
#!/bin/bash
sleep 10
echo SETUP.sh time now: `date +"%T" `
mongo --host mongo1:27017 <<EOF
var cfg = {
"_id": "rs0",
"version": 1,
"members": [
{
"_id": 0,
"host": "mongo1:27017",
"priority": 2
},
{
"_id": 1,
"host": "mongo2:27017",
"priority": 0
},
{
"_id": 2,
"host": "mongo3:27017",
"priority": 0
}
]
};
rs.initiate(cfg, { force: true });
rs.reconfig(cfg, { force: true });
db.getMongo().setReadPref('nearest');
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment