docs/docs/endpoints-test/mongo.md
To test the MongoDB Health Check endpoint, use the following curl command:
curl http://localhost:PORT/health
The Health function checks the health of the MongoDB by pinging it. It returns a simple map containing a health message.
Ping MongoDB Server: The function pings the MongoDB thru server to check its availability.
The Health returns a JSON-like map structure with a single key indicating the health status:
{
"message": "It's healthy"
}
func (s *service) Health() map[string]string {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
err := s.db.Ping(ctx, nil)
if err != nil {
log.Fatalf("db down: %v", err)
}
return map[string]string{
"message": "It's healthy",
}
}
MongoDB does not support advanced health check functions like SQL databases or Redis. The implementation is basic, providing only a simple ping response to indicate if the server is reachable and DB connection healthy.