set server selection timeout to fail early
@@ -37,7 +37,7 @@ func main() {
func DatabaseConnection() (*mongo.Database, error) {
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
- client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://username:password@localhost:27017/fiber"))
+ client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://username:password@localhost:27017/fiber").SetServerSelectionTimeout(5*time.Second))
if err != nil {
return nil, err
}
