MongoError: auth failed to connect to mongoose

I can connect to DB via terminal, but I get this error using mongoose and gulp. mongoose /node_modules/mongodb/lib/mongodb/connection/base.js:246 MongoError: auth failed

My connection string:

mongodb://usr:psw@localhost:27017/dbname

Any idea what this could be?

+4
source share
4 answers

I installed MEAN on https://bitnami.com/stack/mean for Windows 7. When I install, I make the password 123456

Syntax make connect to mongodb with mongoose

mongoose.connect("mongodb://[usr]:[pwd]@localhost:[port]/[db]",{auth:{authdb:"admin"}});

If you haven't

{auth:{authdb:"admin"}}

The error message "MongoError: auth failed" appears

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
+17
source

You might want to do something like this ...

var opt = {
    user: config.username,
    pass: config.password,
    auth: {
        authdb: 'admin'
    }
};
var connection = mongoose.createConnection(config.database.host, 'mydatabase', config.database.port, opt);

'authdb' - , .

+4

, dbname? , . , mongodb://localhost:27017/dbname , .

+3

hier, , mongo, SCRAM-SHA-1 MongoDB-CR. , MongoDB-CR.

MongoDB-CR

+1

All Articles