-
-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeORM for MongoDB with mongodb+srv: HealthCheck reports DB down though NestJS TypeORM connected successfully #1102
Comments
Hi @SvendDomdey, I advise you to leave a minimal reproduction of a clonable git repository so that the core team can evaluate the problem you have reported. |
HI @Tony133, |
@SvendDomdey for database connection maybe you can create a docker compose file, i think it should be fine. |
Hi @Tony133, I have created a minimal repository at https://github.com/SvendDomdey/nestjs-terminus-issue-1102.git. After cloning, you can GET or POST
to see that the DB connection is up & running. But on
the health check fails as described. |
Hi @SvendDomdey, In your minimal repository by doing
gives me this: does not return this answer to you? you tried on the configuration of TypeOrmModule in the url to put everything in string without the template strings ( ${ } ) |
Hi Tony, with my computer, when I do the following
and then query my browser (Chrome latest) on
That is completely different from what you have. For us, this only happened when we accidentally had a MongoDB still running on our local machine at the very same port 27017. Since it's not relevant to what we configured, it must not be running. Regarding your comment, I have tried with and without template strings. Does not make a difference - the app connection works (I can read photos from the DB) but the health check fails. Would it be possible to provide a hint where the URL would actually be used? Then I might do a bit of debugging there. Thanks & kind regards |
Thanks! This worked for us! Thanks @abt0 for providing the fix. |
Hi, my health check isnt working with mongo now
|
I'm submitting a...
Current behavior
TypeOrmHealthIndicator does not work when MongoDB is used and the TypeORM connection to MongoDB was established by a remote URL.
Sample TypeOrmModuleOptions config:
This makes TypeORM successfully connect to the remote database in our use case.
The TypeORM Health check, however, fails. We trigger it with
From debugging it seems that in method checkMongoDBConnection in typeorm.health.ts the connection options are not working properly to build the right URL.
terminus/lib/health-indicator/database/typeorm.health.ts
Line 80 in 08a97a8
During the startup of the app (successful connection to DB over TypeORM) the options.type that is handed over to the MongoDriver is
for the config above. On contrary, for the health check the options.type is only
as entered in the TypeOrmModuleOptions config. To our understanding a mapping from type mongodb to mongodb+srv needs to be performed in between.
In the end we get the error
from the health check - even though our app is up and connected to MongoDB via NestJS TypeORM.
Expected behavior
If NestJS TypeORM connection works, the health check must be able to connect as well and return the correct health result
Minimal reproduction of the problem with instructions
Environment
Thanks for your help & kind regards
Svend
The text was updated successfully, but these errors were encountered: