Replace NewClient with mongo.Connect

This commit is contained in:
Juan Calderon-Perez
2023-11-16 08:22:40 -05:00
committed by GitHub
parent 4b89c87336
commit 9190b12c2e
2 changed files with 8 additions and 6 deletions

View File

@@ -53,11 +53,13 @@ func New(config ...Config) *Storage {
}
// Set mongo options
opt := options.Client()
opt.ApplyURI(dsn)
opt := options.Client().ApplyURI(dsn)
// Create mongo client
client, err := mongo.NewClient(opt)
// Create and connect the mongo client in one step
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
client, err := mongo.Connect(ctx, opt)
if err != nil {
panic(err)
}