MongoError: auth failed mongoose connection string

前端 未结 11 1646
一向
一向 2020-12-29 07:10

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

11条回答
  •  旧巷少年郎
    2020-12-29 08:01

    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' option is the database you created the user under.

提交回复
热议问题