-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bash script that creates mongodb indexes for imbo (#452)
* bash script that creates mongodb indexes for imbo
- Loading branch information
1 parent
e84c84a
commit e2cfeaa
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
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
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 |