Skip to content

Commit 04d17a5

Browse files
committed
fix connection_info not connecting properly
1 parent faa85e9 commit 04d17a5

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ The bootstrap script installs MongoDB, configures it with proper security settin
146146

147147
## Step 2: Provision TLS Certificates
148148

149-
The provision_ssl script configures MongoDB to use pre-generated private CA certificates for enhanced security.
149+
The provision_ssl script configures MongoDB to use pre-generated private CA certificates for enhanced security. These can be generated using the mongodb-ssl tools on your machine.
150150

151151
1. **Place your private CA certificates in the required locations**:
152152

connection_info.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ TEMP_FILE=$(mktemp)
5555
# Store the original domain name for the connection string
5656
CONNECTION_DOMAIN="$DOMAIN"
5757

58-
# Try to connect using the domain name first (if not localhost)
59-
if [ "$DOMAIN" != "localhost" ]; then
60-
echo "Attempting to connect to MongoDB using domain name: $DOMAIN"
61-
if mongosh --host $DOMAIN --port $MONGO_PORT $TLS_ARGS -u $DB_USERNAME -p $DB_PASSWORD --authenticationDatabase admin --quiet --eval "JSON.stringify(rs.status())" > $TEMP_FILE 2>/dev/null; then
62-
echo "✅ Successfully connected to MongoDB using domain name: $DOMAIN"
63-
else
64-
echo "Connection using domain name failed. Trying localhost..."
65-
# If that fails, try connecting using localhost
66-
if mongosh --host localhost --port $MONGO_PORT $TLS_ARGS -u $DB_USERNAME -p $DB_PASSWORD --authenticationDatabase admin --quiet --eval "JSON.stringify(rs.status())" > $TEMP_FILE 2>/dev/null; then
58+
# Try to connect using the domain name first (if not localhost)
59+
if [ "$DOMAIN" != "localhost" ]; then
60+
echo "Attempting to connect to MongoDB using domain name: $DOMAIN"
61+
if mongosh --host $DOMAIN --port $MONGO_PORT --tls --tlsCAFile $CA_FILE --tlsCertificateKeyFile /etc/ssl/mongodb/client.pem -u $DB_USERNAME -p $DB_PASSWORD --authenticationDatabase admin --quiet --eval "JSON.stringify(rs.status())" > $TEMP_FILE 2>/dev/null; then
62+
echo "✅ Successfully connected to MongoDB using domain name: $DOMAIN"
63+
else
64+
echo "Connection using domain name failed. Trying localhost..."
65+
# If that fails, try connecting using localhost
66+
if mongosh --host localhost --port $MONGO_PORT --tls --tlsCAFile $CA_FILE --tlsCertificateKeyFile /etc/ssl/mongodb/client.pem -u $DB_USERNAME -p $DB_PASSWORD --authenticationDatabase admin --quiet --eval "JSON.stringify(rs.status())" > $TEMP_FILE 2>/dev/null; then
6767
echo "✅ Successfully connected to MongoDB using localhost."
6868
# Note: We're not changing CONNECTION_DOMAIN, only the DOMAIN for the current connection
6969
DOMAIN="localhost"
@@ -76,7 +76,7 @@ if [ "$DOMAIN" != "localhost" ]; then
7676
else
7777
# Just try localhost
7878
echo "Attempting to connect to MongoDB using localhost"
79-
if mongosh --host localhost --port $MONGO_PORT $TLS_ARGS -u $DB_USERNAME -p $DB_PASSWORD --authenticationDatabase admin --quiet --eval "JSON.stringify(rs.status())" > $TEMP_FILE 2>/dev/null; then
79+
if mongosh --host localhost --port $MONGO_PORT --tls --tlsCAFile $CA_FILE --tlsCertificateKeyFile /etc/ssl/mongodb/client.pem -u $DB_USERNAME -p $DB_PASSWORD --authenticationDatabase admin --quiet --eval "JSON.stringify(rs.status())" > $TEMP_FILE 2>/dev/null; then
8080
echo "✅ Successfully connected to MongoDB using localhost."
8181
else
8282
echo "❌ ERROR: Failed to connect to MongoDB using localhost."

0 commit comments

Comments
 (0)