-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-mongo.sh
More file actions
21 lines (19 loc) · 756 Bytes
/
init-mongo.sh
File metadata and controls
21 lines (19 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
set -e;
# a default non-root role
MONGO_NON_ROOT_ROLE="${MONGO_NON_ROOT_ROLE:-readWrite}"
echo ">>>>>>> Creating database and users..."
if [ -n "${MONGO_DATABASE_USERNAME:-}" ] && [ -n "${MONGO_DATABASE_PASSWORD:-}" ]; then
mongo -u $MONGO_INITDB_ROOT_USERNAME -p $MONGO_INITDB_ROOT_PASSWORD <<-EOF
db=db.getSiblingDB("$MONGO_INITDB_DATABASE");
use $MONGO_INITDB_DATABASE
db.createUser({
user: $(_js_escape "$MONGO_DATABASE_USERNAME"),
pwd: $(_js_escape "$MONGO_DATABASE_PASSWORD"),
roles: [ { role: $(_js_escape "$MONGO_NON_ROOT_ROLE"), db: $(_js_escape "$MONGO_INITDB_DATABASE") } ]
})
EOF
else
echo "Database and user creation failed. The variables listed in .env.sample must be provided in a .env file."
exit 403
fi