Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions 4.2/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,8 @@ if [ "$originalArgOne" = 'mongod' ]; then
sleep 1
done

rootAuthDatabase='admin'
if [ "$MONGO_INITDB_ROOT_USERNAME" ] && [ "$MONGO_INITDB_ROOT_PASSWORD" ]; then
rootAuthDatabase='admin'

"${mongo[@]}" "$rootAuthDatabase" <<-EOJS
db.createUser({
user: $(_js_escape "$MONGO_INITDB_ROOT_USERNAME"),
Expand All @@ -325,6 +324,16 @@ if [ "$originalArgOne" = 'mongod' ]; then

export MONGO_INITDB_DATABASE="${MONGO_INITDB_DATABASE:-test}"

if [ "$MONGO_USERNAME" ] && [ "$MONGO_PASSWORD" ]; then
"${mongo[@]}" "$rootAuthDatabase" <<-EOJS
db.createUser({
user: $(_js_escape "$MONGO_USERNAME"),
pwd: $(_js_escape "$MONGO_PASSWORD"),
roles: [ { role: 'readWrite', db: $(_js_escape "$MONGO_INITDB_DATABASE") } ]
})
EOJS
fi

echo
for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
Expand Down