# MongoServerError: connection pool exhausted: maxPoolSize of 100 reached

- **ID:** `mongodb/atlas-connection-pool-exhausted`
- **Domain:** mongodb
- **Category:** resource_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

The application opened more connections than the maxPoolSize limit, often due to unclosed cursors or connection leaks.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| mongodb 7.0 | active | — | — |
| mongodb 6.0 | active | — | — |
| mongodb 5.0 | active | — | — |
| mongodb 4.4 | active | — | — |
| mongodb-atlas 1.0 | active | — | — |

## Workarounds

1. **Ensure all cursors are closed in a try-finally block: try { cursor = collection.find(); ... } finally { cursor.close(); }** (90% success)
   ```
   Ensure all cursors are closed in a try-finally block: try { cursor = collection.find(); ... } finally { cursor.close(); }
   ```
2. **Set a lower maxPoolSize and monitor connections: MongoClient.connect(uri, { maxPoolSize: 50, minPoolSize: 10 })** (75% success)
   ```
   Set a lower maxPoolSize and monitor connections: MongoClient.connect(uri, { maxPoolSize: 50, minPoolSize: 10 })
   ```

## Dead Ends

- **** — Leaks will still exhaust the pool eventually, and high connections may overwhelm the server. (80% fail)
- **** — The leak will reoccur and exhaust the pool again. (90% fail)
