【发布时间】:2022-11-24 01:54:35
【问题描述】:
我能够使用 amd64/mongo 将 mongo 容器版本 4.X 和 5.X 与以下代码连接起来
auth := options.Credential{
AuthSource: admin,
Username: userName,
Password: pass,
}
opts := options.Client().ApplyURI(URI).SetAuth(auth).SetTLSConfig(&config)
client, err := mongo.Connect(ctx, opts)
但是当我尝试将容器从 amd64/mongo 升级到版本 6.0.2 时
它失败并出现以下错误
:Unable to connect to thecrdatabase :connection() error occurred during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.
我相信默认情况下它会尝试选择SCRAM-SHA-1
我是否需要像下面这样在我的 mongo 运行脚本文件中设置一个 mongoDB 服务器param?
--authenticationMechanisms=SCRAM-SHA-1
我想要做的就是连接到数据库并使用以下代码更改管理员和数据库密码,即使现在在 mongo 版本中已经贬值也不确定 6.0.2
res := struct{ Ok int }{}
opts := options.RunCmd().SetReadPreference(readpref.Primary())
command := bson.D{{"updateUser", usrName}, {"pwd", pass}}
err = client.Database(db).RunCommand(context.TODO(), command, opts).Decode(&res)
不确定我哪里出错了,错误消息不是直截了当的。有人能帮我一下吗 ?
【问题讨论】:
标签: mongodb docker go x86-64 driver