# MongoError: connection pool exhausted

- **ID:** `data/mongodb-connection-pool-exhausted`
- **Domain:** data
- **Category:** resource_error
- **Error Code:** `MongoError`
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

All connections in the MongoDB driver's connection pool are in use and no new connections can be created, typically due to slow queries or insufficient pool size.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| MongoDB 5.0 | active | — | — |
| MongoDB 6.0 | active | — | — |
| MongoDB 7.0 | active | — | — |
| Node.js driver 4.0+ | active | — | — |

## Workarounds

1. **Increase maxPoolSize and add connection pooling monitoring to detect slow operations. In Node.js: `const client = new MongoClient(uri, { maxPoolSize: 100 });`** (75% success)
   ```
   Increase maxPoolSize and add connection pooling monitoring to detect slow operations. In Node.js: `const client = new MongoClient(uri, { maxPoolSize: 100 });`
   ```
2. **Optimize slow queries by adding indexes and using explain() to identify full collection scans. Example: `db.collection.createIndex({ field: 1 });`** (85% success)
   ```
   Optimize slow queries by adding indexes and using explain() to identify full collection scans. Example: `db.collection.createIndex({ field: 1 });`
   ```
3. **Implement connection pool draining and retry logic in application code to gracefully handle transient exhaustion.** (70% success)
   ```
   Implement connection pool draining and retry logic in application code to gracefully handle transient exhaustion.
   ```

## Dead Ends

- **** — More connections increase contention and memory usage on the server, causing slower queries and more timeouts. (65% fail)
- **** — The root cause (slow queries or insufficient indexing) remains unaddressed. (40% fail)
- **** — Timeouts may kill slow queries but don't fix the underlying performance issue, leading to data inconsistency. (55% fail)
