MongoError: Authentication failed
See original GitHub issueI have mongodb in mongolab. If I connect to it by command
mongo uri/$db -u user -p pass
it is ok. If I use mongoose and connect by
mongoose.connect('mongodb://${user}:${pass}@${uri}/${db}')
I have error
MongoError: Authentication failed
I use mongoose 4.6.1
Issue Analytics
- State:
- Created 7 years ago
- Comments:10
Top Results From Across the Web
MongoError: Authentication failed - MongoDB
Authentication failed means wrong user name, wrong password or wrong authentication database. system (system) closed September 14, 2022, ...
Read more >Unable to connect to mongolab, Getting MongoError: auth failed
When I am trying to connect to the database using the below statement. var mongoose = require('mongoose'); mongoose.connect('mongodb://mk:12345 ...
Read more >MongoError: Authentication failed - Hackolade
MongoError : Authentication failed · 1) Open Compass, select the connection, and click on the Edit button: Compass connection copy 1 ·...
Read more >MongoDB Error Auth failed - Method to set it up correctly
Securing data is always a primary concern in database management. Usually, MongoDB error auth failed, occurs when using an improper ...
Read more >MongoError: Authentication Failed - The freeCodeCamp Forum
What's happening: I have this error: MongoError: Authentication failed. at MessageStream.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hmm also what database is the user defined on? MongoDB users are scoped to dbs, even if they have cross-db privileges, so if the user you have isn’t defined on
db
you’ll need to put something likemongoose.connect('mongodb://${user}:${pass}@${uri}/${db}?authSource=admin')
if the user is defined on the ‘admin’ db.Also, if you’re on mongodb 3.x, you might be using SCRAM-SHA-1 auth or not. Try both of the below:
mongoose.connect('mongodb://${user}:${pass}@${uri}/${db}?authMechanism=SCRAM-SHA-1')
mongoose.connect('mongodb://${user}:${pass}@${uri}/${db}?authMechanism=MONGODB-CR')
just add
?authSource=yourDB&w=1
to end of db urlmongoose.connect('mongodb://user:password@host/yourDB?authSource=yourDB&w=1')
this work for me .&w=1
is important