fix: MongoDB init

This commit is contained in:
Sun-ZhenXing
2025-10-23 18:11:46 +08:00
parent bd84484bcc
commit af55ba73c0
2 changed files with 9 additions and 3 deletions

View File

@@ -49,6 +49,7 @@ services:
mongo-init: mongo-init:
<<: *default <<: *default
image: mongo:${MONGO_VERSION:-8.0.13} image: mongo:${MONGO_VERSION:-8.0.13}
restart: on-failure
depends_on: depends_on:
mongo1: mongo1:
condition: service_healthy condition: service_healthy
@@ -66,11 +67,13 @@ services:
- -c - -c
- | - |
set -e set -e
echo "Waiting for MongoDB node to be ready..." echo "Waiting for MongoDB nodes to be ready..."
sleep 5 sleep 5
mongosh \ mongosh \
--host "mongodb://$${MONGO_INITDB_ROOT_USERNAME}:$${MONGO_INITDB_ROOT_PASSWORD}@$${MONGO_HOST}:$${MONGO_PORT_1}" \ --host "$${MONGO_HOST}:$${MONGO_PORT_1}" \
--username "$${MONGO_INITDB_ROOT_USERNAME}" \
--password "$${MONGO_INITDB_ROOT_PASSWORD}" \
--authenticationDatabase admin \ --authenticationDatabase admin \
--eval " --eval "
const config = { const config = {

View File

@@ -58,6 +58,7 @@ services:
mongo-init: mongo-init:
<<: *default <<: *default
image: mongo:${MONGO_VERSION:-8.0.13} image: mongo:${MONGO_VERSION:-8.0.13}
restart: on-failure
depends_on: depends_on:
mongo1: mongo1:
condition: service_healthy condition: service_healthy
@@ -85,7 +86,9 @@ services:
sleep 5 sleep 5
mongosh \ mongosh \
--host "mongodb://$${MONGO_INITDB_ROOT_USERNAME}:$${MONGO_INITDB_ROOT_PASSWORD}@$${MONGO_HOST}:$${MONGO_PORT_1}" \ --host "$${MONGO_HOST}:$${MONGO_PORT_1}" \
--username "$${MONGO_INITDB_ROOT_USERNAME}" \
--password "$${MONGO_INITDB_ROOT_PASSWORD}" \
--authenticationDatabase admin \ --authenticationDatabase admin \
--eval " --eval "
const config = { const config = {