Skip to content

Instantly share code, notes, and snippets.

@mikehazell
Created January 22, 2019 01:52
Show Gist options
  • Save mikehazell/5a176db4b7b347e48c7cf2617b2dd903 to your computer and use it in GitHub Desktop.
Save mikehazell/5a176db4b7b347e48c7cf2617b2dd903 to your computer and use it in GitHub Desktop.
Shell Script to switch between homebrew Mongo DB versions
# Switching from v3.4 to latest
select_lastest() {
# Stop and unlink 3.4
brew services stop [email protected]
brew unlink [email protected]
# Link last version
brew unlink mongodb && brew link mongodb
# Update mongo logs and database paths
sed -i.3.4 's:/mongodb-3\.4/:/mongodb/:' /usr/local/etc/mongod.conf
# Restart the service
brew services restart mongodb
}
select_34() {
# Stop and Unlink
brew services stop mongodb
brew unlink mongodb
# Link 3.4
brew unlink [email protected] && brew link [email protected] --force
# Update mongo logs and database paths
sed -i.latest 's:/mongodb/:/mongodb-3\.4/:' /usr/local/etc/mongod.conf
# Restart the service
brew services restart [email protected]
}
if [ $1 == 'latest' ]
then
select_lastest
elif [ $1 == '3.4' ]
then
select_34
else
printf Passed: $1
printf Usage: mongo-use [latest|3.4]
fi
printf Current mongo version:
mongo --version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment