From 44c22837dd0e4aa6fb1a8fa99f9efcef96188554 Mon Sep 17 00:00:00 2001 From: Nadeem Shahzad Date: Fri, 27 Aug 2021 16:59:13 +0500 Subject: [PATCH] chore: add mongo 4.2 upgrde script (#828) --- upgrade_mongo_4_2.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 upgrade_mongo_4_2.sh diff --git a/upgrade_mongo_4_2.sh b/upgrade_mongo_4_2.sh new file mode 100755 index 0000000000..e0738475ae --- /dev/null +++ b/upgrade_mongo_4_2.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +set -eu -o pipefail + +# This script will upgrade a devstack that was previosly running Mongo DB 4.0 to MongoDB 4.0 + +. scripts/colors.sh + +# Upgrade to mongo 4.2 +export MONGO_VERSION=4.2.14 + +echo +echo -e "${GREEN}Restarting Mongo on version ${MONGO_VERSION}${NC}" +make dev.up.mongo +mongo_container="$(make --silent --no-print-directory dev.print-container.mongo)" + +echo -e "${GREEN}Waiting for MongoDB...${NC}" +until docker exec "$mongo_container" mongo --eval 'db.serverStatus()' &> /dev/null +do + printf "." + sleep 1 +done + +echo -e "${GREEN}MongoDB ready.${NC}" +MONGO_VERSION_LIVE=$(docker exec -it "$mongo_container" mongo --quiet --eval "printjson(db.version())") +MONGO_VERSION_COMPAT=$(docker exec -it "$mongo_container" mongo --quiet \ + --eval "printjson(db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )['featureCompatibilityVersion'])") +echo -e "${GREEN}Mongo Server version: ${MONGO_VERSION_LIVE}${NC}" +echo -e "${GREEN}Mongo FeatureCompatibilityVersion version: ${MONGO_VERSION_COMPAT}${NC}" + +if echo "${MONGO_VERSION_COMPAT}" | grep -q "4\.0" ; then + echo -e "${GREEN}Upgrading FeatureCompatibilityVersion to 4.2${NC}" + docker exec -it "$mongo_container" mongo --eval "db.adminCommand( { setFeatureCompatibilityVersion: \"4.2\" } )" +else + echo -e "${GREEN}FeatureCompatibilityVersion already set to 4.2${NC}" +fi