Skip to content

Commit

Permalink
'NewClient' is deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
AshokShau committed Aug 18, 2024
1 parent 328b69a commit 84a02b4
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions alita/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package db

import (
"context"
"time"

log "github.com/sirupsen/logrus"

"github.com/divideprojects/Alita_Robot/alita/config"
Expand Down Expand Up @@ -63,16 +61,14 @@ var (
// dbInstance initializes the MongoDB client and collections
func init() {
// Create a new MongoDB client
mongoClient, err := mongo.NewClient(options.Client().ApplyURI(config.DatabaseURI))
mongoClient, err := mongo.Connect(tdCtx, options.Client().ApplyURI(config.DatabaseURI))
if err != nil {
log.Fatalf("[Database][Client]: %v", err)
log.Fatalf("[Database][Connect]: %v", err)
}

ctx, cancel := context.WithTimeout(bgCtx, 10*time.Second)
defer cancel()

if err = mongoClient.Connect(ctx); err != nil {
log.Fatalf("[Database][Connect]: %v", err)
err = mongoClient.Ping(tdCtx, nil)
if err != nil {
log.Fatalf("[Database][Ping]: %v", err)
}

// Get the database reference
Expand Down

0 comments on commit 84a02b4

Please sign in to comment.