以下是我从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)
}
我遇到类似的错误并添加了--authenticationDatabase
参数,并且在我们连接到远程MongoDB时它可以正常工作
在代码中使用以下类似格式:
$mongorestore --host databasehost:98761 --username restoreuser
--password restorepwd --authenticationDatabase admin --db targetdb ./path/to/dump/
[通常,我们将mongoexport命令中的参数与“登录”用户混淆。该命令应使用“数据库用户名”而不是登录用户名。这是输入错误用户名的一种可能性。可以在数据库的“用户”选项卡中找到“数据库用户名”
mgo
返回错误,如果username
,password
或database
错误。检查您的凭据两次。当您可以看到Authentication failed
错误消息时,没有其他情况。
除了上述所有答案,唯一未提及的原因是我的密码中带有特殊字符'$'。我认为使用特殊字符是一种非常常见的做法,如果没有这个简单提示,这可能会使很多人绊倒:
使用命令行mongo / mongostat / etc。时。请单引号您的具有特殊字符的用户名或密码!
您报告的错误似乎是身份验证失败的原因是由nil指针引起的,您应该在使用它们创建连接之前检查数据
与dokku mongo:import一起使用时,我遇到了相同的错误。在我的情况下,我在数据库名称中包含了点(句点)
[dokku mongo:create时,您不应在mongodb名称中包含点号我将其更改为seunghunlee,而不是seunghunlee.net现在此命令有效
dokku mongo:import seunghunlee < seunghunlee.net.dump.gz
希望有帮助!
我能够使用--uri
执行导出。一个例子是mongoexport --uri "mongodb://mongodb0.example.com:27017/reporting" --collection events --out events.json [additional options]
参考docs here。