Arj*_*ith 59 authentication go mongodb mgo
以下是GoLang的MongoDB连接拨号.但它正在返回一个恐慌" 服务器返回SASL身份验证步骤错误:身份验证失败. " 我的用户名,密码,hostAddrs和dbName都是正确的.我在这里错过了什么?
dbName: = os.Getenv("ENV_DBNAME")
userName: = os.Getenv("ENV_DBUSER")
password: = os.Getenv("ENV_DBPASS")
dbHost: = os.Getenv("ENV_DBHOST")
mongoDialInfo: = & mgo.DialInfo {
Addrs: [] string {
dbHost
},
Database: dbName,
Username: userName,
Password: password,
Timeout: 60 * time.Second,
}
sess, err: = mgo.DialWithInfo(mongoDialInfo)
if (err != nil) {
panic(err)
}
Run Code Online (Sandbox Code Playgroud)
小智 129
我遇到类似的错误并添加了--authenticationDatabase参数,它在我们连接到远程MongoDB时工作
在代码中使用以下类似的格式:
$mongorestore --host databasehost:98761 --username restoreuser
--password restorepwd --authenticationDatabase admin --db targetdb ./path/to/dump/
Run Code Online (Sandbox Code Playgroud)
小智 13
我们常常将mongoexport命令中的参数与"Log-In"用户混淆.该命令需要"数据库用户名"不是登录用户名.这是输入错误用户名的一种可能性."数据库用户名"可以在数据库的"用户"选项卡中找到
我从这个链接得到了我的答案:https : //newbiedba.wordpress.com/2016/11/21/mongodb-3-2-server-returned-error-on-sasl-authentication-step-authentication-failed/
除了上面的所有答案,唯一未提及的原因是我的密码中有一个特殊字符“$”。我认为这是具有特殊字符的一种非常常见的做法,如果没有这个简单的提示,这可能会使许多人绊倒:
当使用命令行 mongo/mongostat/etc.. 单引号包含特殊字符的用户名或密码!