how to authenticate mongoose connection mongodb in node.js

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

    Correct way to create the connection string is var connection = mongoose.createConnection("mongodb://username:pwd@hostip:port/dbname?authSource=admin", options);

    Please use authSource=admin to authenticate in connection string.

提交回复
热议问题