簡體   English   中英

連接到 mongodb 容器版本 6.0.2 時出錯 | amd64/蒙戈

[英]Error connecting to mongodb container version 6.0.2 | amd64/mongo

我能夠使用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 thedatabase :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 服務器參數

--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)

不確定我在哪里犯了錯誤,錯誤信息不是直截了當的。 有人能幫我一下嗎?

所以能夠解決這個問題,問題是我的腳本正在使用mongo但它在最新的 mongo 版本6.0中被刪除,所以我使用mongosh ,當我嘗試初始化 mongo 容器時,它起作用了。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM