Skip to content

Commit

Permalink
feat: set mongo pool size
Browse files Browse the repository at this point in the history
  • Loading branch information
dmzlingyin committed May 17, 2024
1 parent 50cb05e commit e838d3e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions config/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func GetBool(field string) bool {
return config.Get(field).Bool()
}

func GetUint64(field string) uint64 {
return config.Get(field).Uint()
}

func SetProfile(profile string) {
config.SetProfile(profile)
}
5 changes: 4 additions & 1 deletion database/mongo/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ func NewDatabase() *mongo.Database {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

client, err := mongo.Connect(ctx, options.Client().ApplyURI(config.GetString("mongo.uri")))
opt := options.Client().ApplyURI(config.GetString("mongo.uri"))
opt.SetMaxPoolSize(config.GetUint64("mongo.max_pool_size"))
opt.SetMinPoolSize(config.GetUint64("mongo.min_pool_size"))
client, err := mongo.Connect(ctx, opt)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit e838d3e

Please sign in to comment.