Skip to content

Commit

Permalink
Exposed the mongo client used in the template.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Cataldo committed Jan 17, 2024
1 parent 6cb0222 commit 6ebc06b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ MongoDB Template
<!--suppress ALL -->
<img align="right" src="gopher-mongo.png" alt="">

[![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)
Expand Down
5 changes: 5 additions & 0 deletions mongo/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions mongo/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,3 +606,8 @@ func TestTemplateListIndexSpecifications(t *testing.T) {
})
}
}

func TestTemplateGetClient(t *testing.T) {
initMongoTemplate()
logger.Info("result:", mongoTemplate.GetClient())
}

0 comments on commit 6ebc06b

Please sign in to comment.