Hi @Leon_D you can just use set -e in your script so exit 1 will happen on an error (which will avoid needing the echo part).
Can you add RUNNER_LOG_FILE=/dev/stderr to the environment section of your compose file (example shown half way down the tutorial you linked) and share the output back here, please? Hopefully this should give us a bit more insight.
Hello, i’m not on the mongo team but am very good at docker/mongo and i’m pretty sure i know what is going on (like 99% confident):
Your mongodb container is starting up, trying to run your import script, but the script is failing because it’s trying to connect to the wrong address with likely incorrect credentials. (the main thing is the wrong address)
The script is running inside the container but is trying to connect as if it were running from outside. The error is fatal enough that it’s causing the entire initialization process to abort, which is why your data isn’t being imported even though the container itself starts.
to fix it do this:
# like the mongo team said
set -e
# Import the test data using the correct internal hostname and credentials
mongoimport --uri "mongodb://${MONGODB_INITDB_ROOT_USERNAME}:${MONGODB_INITDB_ROOT_PASSWORD}@mongodb:27017/?directConnection=true" \
--collection=users \
--db=mydb \
--file=/tmp/users.json
the main bit being:
Using “mongodb:27017” as the connection string (using the service name defined in your docker-compose)
Using port 27017 (internal container port) instead of 27018 (host mapped port)
@Leon_D I think we might need to understand a bit more about your setup. I’ll drop you a DM with an invite to jump on a quick call to see if we can get to the bottom on this one.
Hi @Jonny_Roberts,
Thank you for the input.
Although I definitely tried the "${CONNECTION_STRING}" option before, it now worked, I was probably missing something else. Here is the full script I used:
#!/bin/bash
LOG_FILE="/tmp/mongoimport_error.log"
# Import the test data.
mongoimport --uri "${CONNECTION_STRING}" \
--collection=users \
--db=mydb \
--file=/tmp/users.json \
--jsonArray \
2>> "${LOG_FILE}"
if [ $? -ne 0 ]; then
echo "[ERROR] mongoimport failed" >> "$LOG_FILE"
fi