MongoError: auth failed mongoose connection string

前端 未结 11 1642
一向
一向 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条回答
  •  萌比男神i
    2020-12-29 07:58

    I installed MEAN at https://bitnami.com/stack/mean for windows 7 When install I make password is 123456

    Syntax make connect to mongodb with mongoose

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

    If have no

    {auth:{authdb:"admin"}}
    

    You will get error message "MongoError: auth failed"

    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
    

提交回复
热议问题