mongodb - 服务器在 SASL 身份验证步骤 : Authentication failed

以下是我从 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/

相关文章:

javascript - 从 mongodb id 获取时间戳

node.js - 如何在 Mongoose 中创建和使用枚举

mongodb - 对 mongodb 中的大量记录进行缓慢分页

mysql - 将数据库从 mysql 转换为 mongoDb

regex - Mongo中不区分大小写的搜索

c# - 如何在C#中获取连接字符串中指定的Mongo数据库

node.js - 为什么建议不要在 Node.js 代码的任何地方关闭 MongoDB 连接?

performance - Mongodb聚合框架比map/reduce更快吗?

mongodb - 如何在 MongoDB 中重命名集合?

mongodb - 如何替换mongodb文档中的子字符串