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