-
Notifications
You must be signed in to change notification settings - Fork 215
/
script.sh
executable file
·25 lines (22 loc) · 881 Bytes
/
script.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash
# vim:sw=4:ts=4:et:ai:ci:sr:nu:syntax=sh
##############################################################
# Usage ( * = optional ): #
# ./script.sh *<db-address> *<db-port> *<username> *<password> #
##############################################################
if [ ! -z "$3" ]; then
if [ ! -z "$4" ]; then
echo "Using password authentication!"
auth="--authenticationDatabase admin -u $3 -p $4"
fi
fi
HOST=${1:-localhost} # default server is the localhost
PORT=${2:-27017} # default port for MongoDB is 27017
for directory in *; do
if [ -d "${directory}" ] ; then
echo "$directory"
for data_file in $directory/*; do
mongoimport --drop --host $HOST --port $PORT --db "$directory" --collection "$(basename $data_file .json)" --file $data_file $auth
done
fi
done