[GODRIVER-2647] Error connecting to mongodb container version 6.0.2 | amd64/mongo Created: 09/Nov/22  Updated: 27/Oct/23  Resolved: 28/Nov/22

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Critical - P2
Reporter: karthick d Assignee: Matt Dale
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

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 thecrdatabase :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 params 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 . Mongo doesn't give the actual error . Can anyone help me here ? 



 Comments   
Comment by Matt Dale [ 28/Nov/22 ]

karthickcseapitam@gmail.com I'm glad you were able to resolve the problem! Closing this ticket.

Comment by karthick d [ 25/Nov/22 ]

@Matt Dale , Please mark this as resolved and close this ticket please .

Comment by karthick d [ 23/Nov/22 ]

@Matt Dale 

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, As simple as that , but it was really confusing when we get irrelevant error when the connection failure happens , if that can be improved then it would have been a bit easy !! 

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

Comment by karthick d [ 23/Nov/22 ]

@Matt Dale I tried the way you suggested , But still I get the same 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.

This time I did not even specify the authMechanism in the connection code , but not sure why does this says that unable to authenticate using mechanism "SCRAM-SHA-1"

 

    info := options.Credential{
        AuthSource: db,
        Username:   dbUserName,
        Password:   dbPw,
    }
 
    clientOpts := options.Client().ApplyURI(SOMEURI).SetAuth(auth)
    client, err := mongo.Connect(ctx, clientOpts) 

I tried the same code with mongo container versions 4.4 , 5.0 both works fine , seems like it has only problem with mongo version 6.0 , Not sure if the connection needs some more parameters , not sure what am I missing here .  By the way I'm using the mongo container image from docker hub https://hub.docker.com/r/amd64/mongo/ 

Comment by Matt Dale [ 14/Nov/22 ]

karthickcseapitam@gmail.com I believe that SCRAM-SHA-1 credentials are not created by default in MongoDB 6.0. Drivers typically default to SCRAM-SHA-256 authentication, which is also the default SCRAM password authentication mechanism for MongoDB 6.0. In a previous ticket (GODRIVER-2609), I recommended adding authMechanism=SCRAM-SHA-1 to the connection string to force the driver to use SCRAM-SHA-1 for compatibility when migrating from mgo. Is it possible you're still using a connection string with that authMechanism option in it? If so, please remove that authMechanism option from the connection string and try to connect again.

Also, the GODRIVER Jira is primarily used for Go Driver bug and feature tracking, but is not the right place for asking user support questions. For future requests like this, please use one of the following resources:

  • Our MongoDB support portal, located at support.mongodb.com
  • Our MongoDB community portal, located here
  • If you are an Atlas customer, you can also: Click the in-app chat icon in the lower right corner to chat with a MongoDB Support representative OR Click Support in the left-hand navigation to view Developer Resources.

Thanks!

Generated at Thu Feb 08 08:39:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.