以下是我从 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)
}
原文由 Arjun Ajith 发布,翻译遵循 CC BY-SA 4.0 许可协议
我遇到了类似的错误并添加了
--authenticationDatabase
参数,它在我们连接到远程 MongoDB 时有效在您的代码中使用类似的以下格式: