fix: enhance MongoDB client connection error handling

- Added a ping check after establishing a MongoDB client connection to ensure the connection is valid.
- Implemented error logging for ping failures to improve debugging and provide clearer feedback on connection issues.
- Ensured alignment with existing error handling practices in the codebase for consistency and maintainability.
This commit is contained in:
Marvin Zhang
2025-04-03 12:14:20 +08:00
parent 65d344a21e
commit 04d803f7c9

View File

@@ -136,6 +136,11 @@ func newMongoClient(_opts *ClientOptions) (c *mongo.Client, err error) {
if err != nil {
return err
}
err = c.Ping(ctx, nil)
if err != nil {
logger.Errorf("ping mongo error: %v", err)
return err
}
logger.Infof("connected to mongo")
return nil
}