Answer the question
In order to leave comments, you need to log in
How to connect from Go to mongodb in docker with authorization?
Good afternoon!
There is a Go code in a docker container:
mc, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://"+user+":"+password+"@"+host+":"+port+"/"+common.StoreName))
if err != nil {
return fmt.Errorf("Mongo connection error: %+v", err)
}
err = mc.Ping(ctx, readpref.Primary())
if err != nil {
return fmt.Errorf("Mongo connection ping: %+v", err)
}
mongodb:
container_name: mongodb
image: mongo:latest
environment:
MONGO_INITDB_ROOT_USERNAME: user
MONGO_INITDB_ROOT_PASSWORD: password
MONGO_INITDB_DATABASE: database
volumes:
- './data:/data/db'
Mongo connection ping: connection() : auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question