root@hc4nas02:/var/log# grep error mongoDB-ys20220317.log

1. May 18 06:42:07 192.168.2.250 1 2024-05-18T06:42:07+08:00 YuShei-Parking-System-API - - - - {"t":{"$date":"2024-05-18T06:42:07.707+08:00"},"s":"I",  "c":"CONNPOOL", "id":22572,   "ctx":"MirrorMaestro","msg":"Dropping all pooled connections","attr":{"hostAndPort":"redisMongo05.yushei.com.tw:27017","error":"ConnectionPoolExpired: Pool for redisMongo05.yushei.com.tw:27017 has expired."}}

2. May 18 07:13:49 192.168.2.250 1 2024-05-18T07:13:49+08:00 YuShei-Parking-System-API - - - - {"t":{"$date":"2024-05-18T07:13:49.097+08:00"},"s":"I",  "c":"CONNPOOL", "id":22572,   "ctx":"MirrorMaestro","msg":"Dropping all pooled connections","attr":{"hostAndPort":"redisMongo04.yushei.com.tw:27017","error":"ConnectionPoolExpired: Pool for redisMongo04.yushei.com.tw:27017 has expired."}}

3. May 18 08:16:59 192.168.2.250 1 2024-05-18T08:16:59+08:00 YuShei-Parking-System-API - - - - {"t":{"$date":"2024-05-18T08:16:58.408+08:00"},"s":"I",  "c":"CONNPOOL", "id":22572,   "ctx":"MirrorMaestro","msg":"Dropping all pooled connections","attr":{"hostAndPort":"redisMongo04.yushei.com.tw:27017","error":"ConnectionPoolExpired: Pool for redisMongo04.yushei.com.tw:27017 has expired."}}

4. May 18 08:59:03 192.168.2.250 1 2024-05-18T08:59:03+08:00 YuShei-Parking-System-API - - - - {"t":{"$date":"2024-05-18T08:59:02.142+08:00"},"s":"I",  "c":"CONNPOOL", "id":22572,   "ctx":"MirrorMaestro","msg":"Dropping all pooled connections","attr":{"hostAndPort":"redisMongo04.yushei.com.tw:27017","error":"ConnectionPoolExpired: Pool for redisMongo04.yushei.com.tw:27017 has expired."}}

5. May 18 09:49:50 192.168.2.250 1 2024-05-18T09:49:50+08:00 YuShei-Parking-System-API - - - - {"t":{"$date":"2024-05-18T09:49:50.293+08:00"},"s":"I",  "c":"CONNPOOL", "id":22572,   "ctx":"MirrorMaestro","msg":"Dropping all pooled connections","attr":{"hostAndPort":"redisMongo04.yushei.com.tw:27017","error":"ConnectionPoolExpired: Pool for redisMongo04.yushei.com.tw:27017 has expired."}}

6. May 18 10:09:47 192.168.2.250 1 2024-05-18T10:09:47+08:00 YuShei-Parking-System-API - - - - {"t":{"$date":"2024-05-18T10:09:46.644+08:00"},"s":"I",  "c":"CONNPOOL", "id":22572,   "ctx":"MirrorMaestro","msg":"Dropping all pooled connections","attr":{"hostAndPort":"redisMongo05.yushei.com.tw:27017","error":"ConnectionPoolExpired: Pool for redisMongo05.yushei.com.tw:27017 has expired."}}

7. May 18 10:29:40 192.168.2.250 1 2024-05-18T10:29:40+08:00 YuShei-Parking-System-API - - - - {"t":{"$date":"2024-05-18T10:29:40.150+08:00"},"s":"I",  "c":"CONNPOOL", "id":22572,   "ctx":"MirrorMaestro","msg":"Dropping all pooled connections","attr":{"hostAndPort":"redisMongo05.yushei.com.tw:27017","error":"ConnectionPoolExpired: Pool for redisMongo05.yushei.com.tw:27017 has expired."}}

8. May 18 10:55:05 192.168.2.235 1 2024-05-18T10:55:05+08:00 yushei-dtk-server - - - - {"t":{"$date":"2024-05-18T10:55:04.885+08:00"},"s":"I",  "c":"ACCESS",   "id":20249,   "ctx":"conn87","msg":"Authentication failed","attr":{"mechanism":"SCRAM-SHA-1","speculative":false,"principalName":"diteRootAdmin","authenticationDatabase":"admin","remote":"127.0.0.1:36318","extraInfo":{},"error":"UserNotFound: Could not find user \"diteRootAdmin\" for db \"admin\""}}

9. May 18 11:51:36 192.168.2.250 1 2024-05-18T11:51:36+08:00 YuShei-Parking-System-API - - - - {"t":{"$date":"2024-05-18T11:51:36.752+08:00"},"s":"I",  "c":"CONNPOOL", "id":22572,   "ctx":"MirrorMaestro","msg":"Dropping all pooled connections","attr":{"hostAndPort":"redisMongo05.yushei.com.tw:27017","error":"ConnectionPoolExpired: Pool for redisMongo05.yushei.com.tw:27017 has expired."}}
root@hc4nas02:/var/log# grep -c 'diteRootAdmin' mongoDB-ys20220317.log
2
db.adminCommand({ setParameter: 1, slowOpThresholdMs: 100 });

The MongoDB server itself does not provide a direct way to configure client-side settings such as connection timeout and pool size, because these settings are typically controlled by the MongoDB drivers used in your application. However, you can manage some connection-related settings directly on the server-side using the MongoDB shell and configuration files.

Here are some server-side configurations that can impact connections:
1. MongoDB Configuration File (mongod.conf)

You can adjust the server's connection limits and timeouts in the mongod.conf file. This configuration file allows you to set various parameters that MongoDB uses on startup.

For example, you can configure the net section to control the maximum number of incoming connections:

yaml

net:
  port: 27017
  maxIncomingConnections: 1000  # Example value, adjust as needed

2. Using MongoDB Shell Commands

Although you cannot directly set client-side connection timeout and pool size in the MongoDB shell, you can gather server-side information that helps you understand the current load and adjust the server's performance. Here are a few useful commands:
Checking Connection Status

javascript

db.serverStatus().connections

This will give you the current connection statistics, as you've already seen.
Adjusting Server Parameters

Some server parameters can be adjusted dynamically using the setParameter command. However, these are typically more relevant to internal server behavior rather than client connection management.

For example, adjusting the slow operation threshold:

javascript

db.adminCommand({ setParameter: 1, slowOpThresholdMs: 100 });

3. Performance-Related Commands

You can use performance-related commands to monitor and potentially tune your MongoDB server:
Profiling Slow Queries

Enable profiling to log slow queries, which can help you understand performance issues:

javascript

db.setProfilingLevel(1, { slowms: 100 });  // Logs queries slower than 100ms

Monitoring Operations

Use the currentOp command to monitor active operations and see if any are being delayed:


db.currentOp()

May 18 13:58:56 192.168.2.250 1 2024-05-18T13:58:56+08:00 YuShei-Parking-System-API - - - - {"t":{"$date":"2024-05-18T13:58:55.974+08:00"},"s":"I", "c":"COMMAND", "id":48742, "ctx":"conn1198","msg":"Profiler settings changed","attr":{"from":{"level":0,"slowms":100,"sampleRate":1},"to":{"level":1,"slowms":100,"sampleRate":1}}}

May 18 14:00:13 192.168.2.235 1 2024-05-18T14:00:13+08:00 yushei-dtk-server - - - - {"t":{"$date":"2024-05-18T14:00:12.076+08:00"},"s":"I", "c":"COMMAND", "id":51803, "ctx":"conn89","msg":"Slow query","attr":{"type":"command","ns":"YuSheiDB.yuTsaiLprCashJournal","command":{"find":"yuTsaiLprCashJournal","filter":{"plateText":"NMT0867","inTime":"2024-05-18T11:55:30","carType":"motor","status":{"$ne":"99"},"payTime":{"$gte":"2024-03-19T00:00:00"}},"sort":{"outTime":-1},"batchSize":1,"singleBatch":true,"maxTimeMS":1000,"$readPreference":{"mode":"secondaryPreferred"},"readConcern":{"level":"local"},"$db":"YuSheiDB"},"planSummary":"IXSCAN { status: 1 }","keysExamined":191704,"docsExamined":191704,"hasSortStage":true,"cursorExhausted":true,"numYields":191,"nreturned":0,"queryHash":"7C6270CD","planCacheKey":"893DBB2D","locks":{"FeatureCompatibilityVersion":{"acquireCount":{"r":192}},"Global":{"acquireCount":{"r":192}},"Mutex":{"acquireCount":{"r":1}}},"readConcern":{"level":"local","provenance":"clientSupplied"},"storage":{},"remote":"192.168.2.250:39888","protocol":"op_msg","durationMillis":230}}