implemented mongo gridFS for file upload
This commit is contained in:
@@ -204,6 +204,25 @@ func (cm *ConnectionManager) Close(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsConnected checks if MongoDB connection is active
|
||||
func (cm *ConnectionManager) IsConnected() bool {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
|
||||
err := cm.Ping(ctx)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// GetDatabase returns the MongoDB database instance
|
||||
func (cm *ConnectionManager) GetDatabase() *mongo.Database {
|
||||
return cm.database
|
||||
}
|
||||
|
||||
// GetClient returns the MongoDB client instance
|
||||
func (cm *ConnectionManager) GetClient() *mongo.Client {
|
||||
return cm.client
|
||||
}
|
||||
|
||||
// Ping pings the MongoDB server
|
||||
func (cm *ConnectionManager) Ping(ctx context.Context) error {
|
||||
if err := cm.client.Ping(ctx, readpref.Primary()); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user