mongodb
resource_error
ai_generated
true
MongoServerError: connection pool exhausted: maxPoolSize of 100 reached
ID: mongodb/atlas-connection-pool-exhausted
85%Fix Rate
86%Confidence
1Evidence
2023-09-12First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| mongodb 7.0 | active | — | — | — |
| mongodb 6.0 | active | — | — | — |
| mongodb 5.0 | active | — | — | — |
| mongodb 4.4 | active | — | — | — |
| mongodb-atlas 1.0 | active | — | — | — |
Root Cause
The application opened more connections than the maxPoolSize limit, often due to unclosed cursors or connection leaks.
generic中文
应用程序打开的连接数超过了maxPoolSize限制,通常是由于未关闭的游标或连接泄漏。
Official Documentation
https://www.mongodb.com/docs/manual/reference/connection-string-options/#maxPoolSizeWorkarounds
-
90% success Ensure all cursors are closed in a try-finally block: try { cursor = collection.find(); ... } finally { cursor.close(); }
Ensure all cursors are closed in a try-finally block: try { cursor = collection.find(); ... } finally { cursor.close(); } -
75% success Set a lower maxPoolSize and monitor connections: MongoClient.connect(uri, { maxPoolSize: 50, minPoolSize: 10 })
Set a lower maxPoolSize and monitor connections: MongoClient.connect(uri, { maxPoolSize: 50, minPoolSize: 10 })
中文步骤
确保所有游标在try-finally块中关闭:try { cursor = collection.find(); ... } finally { cursor.close(); }设置较低的maxPoolSize并监控连接:MongoClient.connect(uri, { maxPoolSize: 50, minPoolSize: 10 })
Dead Ends
Common approaches that don't work:
-
80% fail
Leaks will still exhaust the pool eventually, and high connections may overwhelm the server.
-
90% fail
The leak will reoccur and exhaust the pool again.