以下是我从 GoLang 获得的 MongoDB 连接拨号。但它返回一个 panic “服务器在 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)
}
最佳答案
我遇到了类似的错误并添加了 --authenticationDatabase
参数,它在我们连接到远程 MongoDB 时工作
在您的代码中使用类似的以下格式:
$mongorestore --host databasehost:98761 --username restoreuser
--password restorepwd --authenticationDatabase admin --db targetdb ./path/to/dump/
关于mongodb - 服务器在 SASL 身份验证步骤 : Authentication failed 上返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38744131/