I can connect to the DB through terminal, but getting this error using mongoose and gulp. mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:246 MongoError: auth failed
My connection string is:
mongodb://usr:psw@localhost:27017/dbname
Any idea what it can be?
I installed MEAN from MEAN packaged by Bitnami for windows 7 using the following password: 123456
Syntax for connection string to connect to mongodb
with mongoose
module
mongoose.connect("mongodb://[usr]:[pwd]@localhost:[port]/[db]",{auth:{authdb:"admin"}});
If you don't have {auth:{authdb:"admin"}}
in the connection string, you will get the following error: MongoError: Authentication failed.
JS Example: mongo-test/app.js
var mongoose = require('mongoose'); mongoose.connect('mongodb://root:123456@localhost/test',{auth:{authdb:"admin"}}); mongoose.set('debug', true); // turn on debug
just add ?authSource=yourDB&w=1
to end of db url
mongoose.connect('mongodb://user:password@host/yourDB?authSource=yourDB&w=1')
this work for me . &w=1
is important
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With