Skip to content

Instantly share code, notes, and snippets.

@William-Yeh
Created April 15, 2014 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save William-Yeh/10718663 to your computer and use it in GitHub Desktop.
Save William-Yeh/10718663 to your computer and use it in GitHub Desktop.
Simple tool to disable MongoDB balancer.
#!/bin/bash
MONGODB_NAME=$1
MONGODB_PASS=$2
MONGODB_HOST=$3
MONGODB_PORT=${4:-27017}
if [ $# -lt 3 ]; then
echo "Simple tool to disable MongoDB balancer."
echo "Usage: disable-mongodb-balancer.sh username password host [port]"
exit 1
fi
echo -e "use admin\ndb.auth('$MONGODB_NAME','$MONGODB_PASS')\nuse config\nsh.setBalancerState(false)\nwhile (sh.getBalancerState() || sh.isBalancerRunning()) { print(false); sleep(5000); }\nprint(true)\n" | mongo --norc --host $MONGODB_HOST --port $MONGODB_PORT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment