-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Mongoose 5.0.1: Authentication failed with authMechanism=SCRAM-SHA-1 in MongoDB docker container #6052
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
Comments
Try this: await Mongoose.connect('mongodb://admin:1234@server-db:27017/server-db?authSource=admin') If I'm reading this correctly, you're connecting to 'server-db' and trying to authenticate against the 'admin' user that's defined on the 'admin' db. You need to tell MongoDB what database your user is defined on regardless of whether you're using docker or not. |
I've tried this but without any luck.. When i change the name of the database from |
@vkarpov15 me and @dlipovac012 are working on the same project. |
@dlipovac012 try |
@vkarpov15 Nope.. Didn't work.. I got the same issue as before, saying: |
@vkarpov15 Do you have more suggestions or is this a bug? |
@BorntraegerMarc @dlipovac012 nope I'm pretty baffled. You're certain that: await Mongoose.connect('mongodb://db-user:4567@server-db:27017/server-db?authSource=test') Does not work but the below does? await Mongoose.connect('mongodb://db-user:4567@server-db:27017/test') |
@vkarpov15 Actually, no. When we create admin user, it gets created in Here's the link to this dummy application that mimics our real application: https://github.com/dlipovac012/nestmongoauth If it helps somehow, here's the screenshot of the terminal with error: |
Turns out there was a misconfiguration in the mongo docker container. We didn't use the env variables specified here: docker-library/mongo#189 Now it works! Thanks for your support! |
@vkarpov15 Brother, this is awesome! I have wasted 4 hours on this issue. Thank you very much! |
Thank you for your help, I had a headache with this issue for my project using .Net Core |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
We have set up a MongoDB docker container and want to connect to it with a custom mongo user. We have tried many connection attempts. Like:
await Mongoose.connect('mongodb://db-user:4567@server-db:27017/admin?authSource=admin');
or:
await Mongoose.connect('mongodb://admin:1234@server-db:27017/server-db?authMechanism=SCRAM-SHA-1');
or:
await Mongoose.connect('mongodb://admin:1234@server-db:27017/server-db');
Then I see in the console:
So according to the logs I'm 100% sure that my backend server and my mongoDB instance have connection to each other. The failure is really at authenticating.
Connecting to the mongodb without username + password like this actually works fine:
await Mongoose.connect('mongodb://server-db:27017/server-db');
-> However of course an exception is thrown as soon as I try to create new collections, etc.If the current behavior is a bug, please provide the steps to reproduce.
My MongoDB file looks like this:
Inside
mongo.config.js
:And actually I see the successful creation of the user in the console:
And logging on a terminal also works:
What is the expected behavior?
Mongoose should connect successfully with the existing username + password.
I have searched through all possible issues in this repository and also on stackoverflow. I have a feeling that this might be a bug when connecting to a docker MongoDB instance.
Please mention your node.js, mongoose and MongoDB version.
Node: v8.9.1
MongoDB: 3.6.2
Mongoose: 5.0.1
The text was updated successfully, but these errors were encountered: