Open jason-fox opened 4 years ago
I discovered this findOne
error message by copy-pasting the yaml from the Docker README.md
documentation directly - there is a repeated typo there which needs fixing since mongodb
and mongo-db
refer to different URLs:
The underlying issue needs to be addressed in the node library though.
@jason-fox +1
It would be great if somebody could contribute with a solution to this issue in the form of PR. It has been labeled with "help wanted". Thanks in advance!
Problem
Imagine the following, I have an IoT Agent, but my database is not present:
At the moment the system will attempt to connect n times and throw appropriate errors on startup:
However after the Nth failure, startup will continue regardless. I can then happily query the
/iot/about
(using it as a heartbeat) and assume everything is fine ... until I attempt to actually do anything with the database e.g. provision a service and the request unhelpfully returns the following:and the log states:
The reason for this failure is quite simple, mongoose cannot create the schema model since it can't connect to a non-existent database.
Solution
Since the IoT Agent is unusable, I guess the start-up should fail completely and exit if the database cannot connect.
The alternative would be to add an undefined check on each invocation of
.model.findOne()
and throw a more appropriate error message.If we're going to fail, we might as well fail in an understandable manner.