Skip to content

Commit 7032706

Browse files
authored
Merge pull request #12 from HasanRothi/master
feat(NoSqlConnection): authSource parameter support
2 parents bf2e7cb + b8c5ec2 commit 7032706

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

mongo.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,13 @@ func getMongoUri() string {
153153
noSqlUserInfo = Config.GetString(Config.NoSqlConfig+".Username") + ":" + password + "@"
154154
}
155155

156-
return noSqlProtocol + noSqlUserInfo + host + "/" + Config.GetString(Config.NoSqlConfig+".Database") + "?retryWrites=true&w=majority"
156+
connectionUri := noSqlProtocol + noSqlUserInfo + host + "/" + Config.GetString(Config.NoSqlConfig+".Database") + "?retryWrites=true&w=majority"
157+
158+
//required parameter for self-hosted mongodb
159+
authSource := Config.GetString(Config.NoSqlConfig + ".AuthSource")
160+
if authSource != "" {
161+
connectionUri = connectionUri + "&authSource=" + authSource
162+
}
163+
164+
return connectionUri
157165
}

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ type DatabaseConfig struct {
135135
Port string `mapstructure:"DB_PORT" default:""`
136136
Database string `mapstructure:"DB_DATABASE" default:""`
137137
Connection string `mapstructure:"DB_CONNECTION" default:""`
138+
AuthSource string `mapstructure:"DB_AUTH_SOURCE" default:""`
138139
}
139140
```
140141
and your `.env` is:
@@ -145,6 +146,7 @@ DB_PORT=
145146
DB_USER=user
146147
DB_PASS=password
147148
DB_DATABASE=collection
149+
DB_AUTH_SOURCE=admin
148150
```
149151

150152
For initialization `DatabaseConfig` config.

0 commit comments

Comments
 (0)