Iam able to connect mongo container versions 4.X and 5.X with the below code using amd64/mongo
auth := options.Credential{
AuthSource: admin,
Username: userName,
Password: pass,
}
opts := options.Client().ApplyURI(URI).SetAuth(auth).SetTLSConfig(&config)
client, err := mongo.Connect(ctx, opts)
But when i try to upgrade the container to version 6.0.2 from amd64/mongo
It fails with the below error
: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.
I believe by default it tries to pick SCRAM-SHA-1
do I need to set a mongoDB server param in my mongo run script file like below ?
--authenticationMechanisms=SCRAM-SHA-1
All i'm trying to do is connect to db and change the admin and db password using below code , not sure even if this is depreciated now in the mongo version 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)
not sure where am i making mistake , the error message is not straight forward . Can anyone help me here ?
So was able to resolve this , The problem was my scripts were using mongo
but that is removed in the latest mongo version 6.0
, So i used mongosh
, when I try to init the mongo container, that worked.