This repository is uploaded for academic learning of database pooling class. I have used official golang mongo-driver for mongodb. For installation please go to your GOPATH and enter the following command:
go get github.com/Mohammed-Aadil/golang-mongo-pool
For pooling following functions are required in class:
Init(string)
CreateConnection() (*mongo.Client, error)
GetDatabase() (*mongo.Database, error)
GetBusyConnectionsCount() int
GetMaxConnections() int
GetMinConnections() int
GetOpenConnections() []*mongo.Client
GetOpenConnectionsCount() int
GetPoolName() string
GetTimeOut() time.Duration
SetErrorOnBusy()
SetPoolSize(uint32, uint32)
TerminateConnection(*mongo.Client)
This function is use for initializing important config of mongo db eg: connection client
This function is used as getObject of pooling class. It will return new connection if required on calling.
This function is call to initialize database and return db instance from mongo client.
This Function return no of busy connection count.
This function return count of maximum allowed connections in pool.
This function return count of minimum allowed connections in pool.
This function return all the open connection instances in pool.
This function return count of open connections in pool.
This function return pool name. Default is root
This function return timeout duration of connection in pool.
If this function is called then if all connections are busy CreateConnection()
function will return MongoPoolError
.
This will resize mongo pool without affecting currently open connection. This function still need to be implemented. All PR for this are welcome.
This will terminate the connection and release same object from pool.