From 6ebc06bcf8ae338c5277d97ab81b91d92b8e31fb Mon Sep 17 00:00:00 2001 From: Gabriel Cataldo Date: Wed, 17 Jan 2024 18:13:55 -0300 Subject: [PATCH] Exposed the mongo client used in the template. --- README.md | 2 +- mongo/template.go | 5 +++++ mongo/template_test.go | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index afc0686..3efb633 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ MongoDB Template -[![Project status](https://img.shields.io/badge/version-v1.0.6-vividgreen.svg)](https://github.com/GabrielHCataldo/go-mongo-template/releases/tag/v1.0.6) +[![Project status](https://img.shields.io/badge/version-v1.0.7-vividgreen.svg)](https://github.com/GabrielHCataldo/go-mongo-template/releases/tag/v1.0.7) [![Go Report Card](https://goreportcard.com/badge/github.com/GabrielHCataldo/go-mongo-template)](https://goreportcard.com/report/github.com/GabrielHCataldo/go-mongo-template) [![Coverage Status](https://coveralls.io/repos/GabrielHCataldo/go-mongo-template/badge.svg?branch=main&service=github)](https://coveralls.io/github/GabrielHCataldo/go-mongo?branch=main) [![Open Source Helpers](https://www.codetriage.com/gabrielhcataldo/go-mongo-template/badges/users.svg)](https://www.codetriage.com/gabrielhcataldo/go-mongo) diff --git a/mongo/template.go b/mongo/template.go index 446544e..7448eff 100644 --- a/mongo/template.go +++ b/mongo/template.go @@ -1013,6 +1013,11 @@ func (t *Template) SimpleDisconnect(ctx context.Context) { logger.Info("connection to mongoDB closed.") } +// GetClient get mongo client used on template +func (t *Template) GetClient() mongo.Client { + return *t.client +} + func (t *Template) insertOne(sc mongo.SessionContext, document any, opt option.InsertOne) error { if util.IsNotPointer(document) { return ErrDocumentIsNotPointer diff --git a/mongo/template_test.go b/mongo/template_test.go index 1b24dd5..5e0373c 100644 --- a/mongo/template_test.go +++ b/mongo/template_test.go @@ -606,3 +606,8 @@ func TestTemplateListIndexSpecifications(t *testing.T) { }) } } + +func TestTemplateGetClient(t *testing.T) { + initMongoTemplate() + logger.Info("result:", mongoTemplate.GetClient()) +}