Skip to content

Commit 68d2cb2

Browse files
authored
bugfix: fix connect to mongodb server bug
When set `DB_USER` and `DB_PASS`,Unable to connect to MongoDB, and throws the following exception: ``` 2023/01/10 15:49:30 The App is running in development env 2023/01/10 07:49:30 connection() error occurred during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed. ```
1 parent f48f761 commit 68d2cb2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

bootstrap/database.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ func NewMongoDatabase(env *Env) mongo.Client {
1919
dbPass := env.DBPass
2020
dbName := env.DBName
2121

22-
mongodbURI := fmt.Sprintf("mongodb://%s:%s@%s:%s/%s", dbUser, dbPass, dbHost, dbPort, dbName)
22+
mongodbURI := fmt.Sprintf("mongodb://%s:%s@%s:%s", dbUser, dbPass, dbHost, dbPort)
2323

2424
if dbUser == "" || dbPass == "" {
25-
mongodbURI = fmt.Sprintf("mongodb://%s:%s/%s", dbHost, dbPort, dbName)
25+
mongodbURI = fmt.Sprintf("mongodb://%s:%s", dbHost, dbPort)
2626
}
2727

2828
client, err := mongo.NewClient(mongodbURI)

0 commit comments

Comments
 (0)