【问题标题】:Error connecting to mongodb container version 6.0.2 | amd64/mongo连接到 mongodb 容器版本 6.0.2 时出错 | amd64/蒙戈
【发布时间】: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


    【解决方案1】:

    所以能够解决这个问题,问题是我的脚本使用的是mongo,但在最新的 mongo 版本6.0 中被删除了,所以我使用了mongosh,当我尝试初始化 mongo 容器时,它起作用了。

    https://www.mongodb.com/docs/mongodb-shell/

    【讨论】:

      猜你喜欢
      • 2020-04-27
      • 2021-11-12
      • 2018-09-28
      • 2019-10-03
      • 2017-10-03
      • 2020-09-24
      • 1970-01-01
      • 1970-01-01
      • 2017-09-13
      相关资源
      最近更新 更多