how to authenticate mongoose connection mongodb in node.js

前端 未结 7 2117
没有蜡笔的小新
没有蜡笔的小新 2021-02-20 04:38

I have created mongodb user with command

use admin
db.createUser(
    {
      user: \"superuser\",
      pwd: \"12345678\",
      roles: [ \"root\" ]
    }
)
         


        
7条回答
  •  别那么骄傲
    2021-02-20 05:28

    mongoose.createConnection('mongodb://username:password@35.238.xxx.xxx:27017/dashboards?authSource=admin', {
       useNewUrlParser: true
    }, (e) => {
    
        if (e) throw console.error('Error connecting to mongo database master');
        console.log('Connected to mongo database master.');
    
    });
    

提交回复
热议问题