# MongoServerError：连接池耗尽：已达到maxPoolSize 100

- **ID:** `mongodb/atlas-connection-pool-exhausted`
- **领域:** mongodb
- **类别:** resource_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

应用程序打开的连接数超过了maxPoolSize限制，通常是由于未关闭的游标或连接泄漏。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| mongodb 7.0 | active | — | — |
| mongodb 6.0 | active | — | — |
| mongodb 5.0 | active | — | — |
| mongodb 4.4 | active | — | — |
| mongodb-atlas 1.0 | active | — | — |

## 解决方案

1. ```
   确保所有游标在try-finally块中关闭：try { cursor = collection.find(); ... } finally { cursor.close(); }
   ```
2. ```
   设置较低的maxPoolSize并监控连接：MongoClient.connect(uri, { maxPoolSize: 50, minPoolSize: 10 })
   ```

## 无效尝试

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