how to authenticate mongoose connection mongodb in node.js

前端 未结 7 2116
没有蜡笔的小新
没有蜡笔的小新 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:43

    You need to create an User in database which you are operating on, not the admin DB.

    Use this command,

    use twitter-mongo;
    db.createUser({
      user: "superuser",
      pwd: "12345678",
      roles: [ "root" ]
    });
    

    Instead of this,

    use twitter-mongo
    db.createUser({
      user: "superuser",
      pwd: "12345678",
      roles: [ "root" ]
    });
    
    0 讨论(0)
提交回复
热议问题