Idiomatic Go Lang Connection Package

dbConnMgr, dbErr := mongodb.NewMongoManager(
	svcEnv.DBHosts,
	svcEnv.DBName,
	dbCredentials,
	mongodb.WithQueryLogging(svcEnv.DBLogQueries),
	mongodb.WithReplicaSet(svcEnv.ReplicaSet) added to demonstrate functional options
)

I wrote a very simple package (with no dependencies other than mongodb driver itself) following go idiomatic patterns to connect to MongoDB and it was well received.

It uses functional ops pattern to support all different connection types supported by MongoDB while keeping it extremely simple for people who are happy with defaults.

Check it out: go-rest-api-example/pkg/mongodb at main · rameshsunkara/go-rest-api-example · GitHub

Repo: GitHub - rameshsunkara/go-rest-api-example: Production-ready Go REST APIs without the enterprise bloat

2 Likes

Thank you for sharing @Ramesh_Sunkara! @Didi who leads up the Community Hub will review later this week!

1 Like

Sure thank you.

This repo was show caused in golang news weekly twice. If the MongoDb team likes it, please let me know how to make it more useful or visible.

1 Like

@Ramesh_Sunkara, this is fantastic! The package looks really clean, and the way you’ve used functional options for things like logging and replica sets is great because it keeps the core connection setup simple while still providing flexibility for anyone who needs customization.

Great work! Thank you for building and sharing it on the MongoDB Community Hub. I will share it internally with the team :smiley:

1 Like