// NewMongoDB - open connect and ping trying
open connect and ping trying
// NewMongoDB - open connect and ping trying
func NewMongoDB(ctx context.Context, cfg Config) (*mongo.Client, error) {
	clientOptions := options.Client()
	clientOptions.SetAuth(options.Credential{
		Username: cfg.Username,
		Password: cfg.Password,
	})
	clientOptions.ApplyURI(cfg.Url)
	dbClient, err := mongo.Connect(ctx, clientOptions)
	if err != nil {
		return nil, fmt.Errorf("mongodb connect: %w", err)
	}
	if err := dbClient.Ping(context.Background(), nil); err != nil {
		return nil, fmt.Errorf("mongodb ping: %w", err)
	}
	return dbClient, nil
}
func NewMongoDB ( ctx context . Context , cfg Config ) ( * mongo . Client , error ) { clientOptions := options . Client ( ) clientOptions . SetAuth ( options . Credential { Username : cfg . Username , Password : cfg . Password , } ) clientOptions . ApplyURI ( cfg . Url ) dbClient , err := mongo . Connect ( ctx , clientOptions ) if err != nil { return nil , fmt . Errorf ( " " , err ) } if err := dbClient . Ping ( context . Background ( ) , nil ) ; err != nil { return nil , fmt . Errorf ( " " , err ) } return dbClient , nil }
open connect and ping trying
open connect and ping trying