File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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```
140141and your ` .env ` is:
@@ -145,6 +146,7 @@ DB_PORT=
145146DB_USER=user
146147DB_PASS=password
147148DB_DATABASE=collection
149+ DB_AUTH_SOURCE=admin
148150```
149151
150152For initialization ` DatabaseConfig ` config.
You can’t perform that action at this time.
0 commit comments