更新时间:2023-12-04 23:25:16
找到解决方案,我没有传递authDatabase名称,这就是连接失败的原因.之前我在用这个
Found the solution, I didn't passed the authDatabase name, that's why the connection failed. Earlier i was using this
mongoose.connect('mongodb://user:password@host:port/dbname')
现在我用了这个
mongoose.connect('mongodb://user:password@host:port/dbname?authSource=dbWithUserCredentials')
在猫鼬本身的讨论线程上找到了该解决方案
Found this solution on Discussion thread of Mongoose itself
别忘了用您自己的内容替换dbWithUserCredentials
.在大多数情况下,dbWithUserCredentials是admin.所有登录凭据(如用户名,密码)均已在传递给mongoose.connect()
的参数中指定.
Don't forget to replace dbWithUserCredentials
with your own. In most cases dbWithUserCredentials would be admin. All the credentials for login like username, password are already specified in the parameter passed to mongoose.connect()
.