how to authenticate mongoose connection mongodb in node.js

前端 未结 7 1942
没有蜡笔的小新
没有蜡笔的小新 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" ]
    });
    

提交回复
热议问题