mongodb - 服务器在 SASL 身份验证步骤 : Authentication failed 上返回错误

标签 mongodb authentication go mgo

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

相关文章:

java - 无法使用 java 连接在 MongoDB 3.0.2 中对用户进行身份验证

angular - 如何根据用户角色显示/隐藏元素 Angular 4

mysql - 使用JSP私有(private)登录向MYSQL数据库添加信息

mongodb - 如何克隆(重复)同一数据库集合中的 MongoDB 对象?

node.js - 如何按下 {key : value} object in my MongoDB array?

node.js - FindOneAndUpdate 与 mongoose 中的模型

go - Project Euler #145 循环中的结果太多

mysql - 有没有更好的方法来编码 sql 行?

api - 在 golang 中以编程方式访问 RPM apis/calls

c# - Mongo C# 驱动程序查找多个并删除