I have a node.js app that uses MongoDB as a database. I have also the management of MongoDB. When the app starts, it connects to MongoDB without any problem. I am trying to let the user defines which database he/she will connect to. To do that I create mongo.conf like that:
And in the app, I defined the connection uri like that: MONGODB_URL="mongodb://< username>:< password>@34.72.5.46:27017/"
The database user has the root role. As I mentioned, in first opening the app connects to the database. In the first opening, I am using mongoose.connect But when the user inserts a database name that doesn't exist, via the app, I am using mongoose.createConnection. And then I get this error:
MongoNetworkError: failed to connect to server [34.72.5.46:27017] on first connect [MongoError: Authentication failed.
What should I do?