Hi, I’m trying to port our dockerized app wrote in NestJS and using Mongoose to app platform. Currently I’m facing errors when connecting to managed MongoDB database.
I’ve tested locally using the params mongo.CA_CERT
and mongo.DATABASE_URL
passed to the app changing the connection string to ${mongo.DATABASE_URL}&tlsCAFile=ca-certificate.crt
and saving the certificate as ca-certificate.crt
in the root of the project, and everything works correctly.
When I do this on app platform using this configuration:
databases:
- name: mongo
engine: MONGODB
production: true
cluster_name: ....
db_name: ....
envs:
- key: DATABASE_URI
value: ${mongo.DATABASE_URL}
scope: RUN_TIME
type: GENERAL
- key: DATABASE_CERT
value: ${mongo.CA_CERT}
scope: RUN_TIME
type: GENERAL
And using as CMD
an executable file with this commands
echo "Database connection string"
echo $DATABASE_URI
echo "Creating cert file..."
echo "${DATABASE_CERT}" > ca-certificate.crt
echo "Created file ca-certificate.crt"
cat ca-certificate.crt
echo "Starting seeding..."
npm run console:prod -- seeder .....
echo "Seeding done."
echo "Starting Server..."
node dist/apps/manager-api/main.js
Everyting is printed correctly and the server starts… but cannot connect to the database.
Also I tryied to use the run_command
to avoid to put the logic for the cert inside the docker container, but even using something like
echo "${DATABASE_CERT}" > ca-certificate.crt && node dist/apps/manager-api/main.js
fails with a Deploy Error: Non-Zero Exit Code
and no logs…
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
OK, for the
run_command
part I think that it’s an issue with docker and how it manages commands… probably I should pass it as an arrayFor the Database I think I found a bug in the system. In the last few days I’ve done some heavy testing destroying and recreating apps, and I think something broke in the db management. When deploying an app, a user is created in the DB. This user is the same in the connection string and in the dashboard of the database section, but accessing directly the DB shows an user with a different name, blocking the connection.
This is the logs of the failed connection from DB
This is the only user starting with
doapps
on the DB at the momentI’ve tried eleminating everything from the user to the collection, but the bug remained.
I’ve istantiated a new DB and everything works correctly now.
This issue can create serious damage, also because it seems to be impossible to add or remove users without using your dashboard…