package utils import ( "context" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" "time" ) func ConnectMongoDB(uri string, username, passwd string) (*mongo.Client, error) { ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) client, err := mongo.Connect(ctx, options.Client().ApplyURI(uri).SetAuth(options.Credential{ Username: username, Password: passwd, })) if err != nil { return nil, err } return client, nil }