Skip to content

Commit

Permalink
bash script that creates mongodb indexes for imbo (#452)
Browse files Browse the repository at this point in the history
* bash script that creates mongodb indexes for imbo
  • Loading branch information
chrisaq authored and christeredvartsen committed Jun 15, 2016
1 parent e84c84a commit e2cfeaa
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions bin/imbo-mongo-indexes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

printf "Usage: $0 [mongo-host[:port]] [database-name] [non-interactive]\n\n"

# Get mongodb host from first arg
if [ -z ${1+x} ]; then
echo "Mongo host is undefined, assuming localhost.";
MONGOHOST="127.0.0.1:27017"
else
echo "Mongo host is set to '$1'";
MONGOHOST="$1"
fi

# Get mongodb database name from second arg
if [ -z ${2+x} ]; then
echo "Database name is undefined, assuming imbo.";
DBNAME="imbo"
else
echo "Database name is set to '$2'";
DBNAME="$2"
fi

# confirm values if interactive
if [ "$#" -gt "2" ]; then
if [ $3 == "non-interactive" ]; then
echo "Not interactive, moving on."
fi
else
echo "Are the above values correct?"
read -p "(yes/no): " CONFIRM
if [ ! ${CONFIRM} == "yes" ]; then
exit 2
fi
fi

mongo ${MONGOHOST}/${DBNAME} <<EOF
db.image.ensureIndex({"user": 1, "imageIdentifier": 1}, { background: true })
db.image.ensureIndex({"user": 1, "added": -1}, { background: true })
db.image.ensureIndex({"user": 1, "updated": -1}, { background: true })
EOF

0 comments on commit e2cfeaa

Please sign in to comment.