Skip to content

Instantly share code, notes, and snippets.

@svenvarkel
Created January 20, 2021 09:37
Show Gist options
  • Save svenvarkel/6bef123860934f6e2ca6b4fe9dc8d577 to your computer and use it in GitHub Desktop.
Save svenvarkel/6bef123860934f6e2ca6b4fe9dc8d577 to your computer and use it in GitHub Desktop.
Create indexes on MongoDB replica set member
#!/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