Created
January 20, 2021 09:37
-
-
Save svenvarkel/6bef123860934f6e2ca6b4fe9dc8d577 to your computer and use it in GitHub Desktop.
Create indexes on MongoDB replica set member
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ -z "$1" ]; | |
then | |
echo "Usage: $0 <index file path>" | |
exit 1 | |
fi | |
export INDEX_FILE="$1" | |
systemctl stop mongod | |
su mongodb --shell /bin/bash -c 'mongod --dbpath /mongodb/data --port 47017 --wiredTigerDirectoryForIndexes --pidfilepath=/tmp/mongod.pid &' | |
while ! nc -z localhost 47017 </dev/null; do sleep 5; done | |
mongo --port 47017 atlas $INDEX_FILE | |
kill $(cat /tmp/mongod.pid) | |
while nc -z localhost 47017 </dev/null; do sleep 5; done | |
systemctl restart mongod |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment