Mongodb command "mongosh" giving error even server is running

I am using MongoDB “version”: “7.0.1”
When I run the command mongosh it is giving me the below error:

Connecting to:          mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.10.6 MongoServerSelectionError: Server selection timed out after 2000 ms"

when i checked the log it seems it is connecting then it is getting disconnected, below is the log.

{"t":{"$date":"2023-09-20T10:28:51.485+05:30"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:62675","uuid":{"uuid":{"$uuid":"8c007f81-c179-4164-8a42-b631ed789239"}},"connectionId":2,"connectionCount":1}}
{"t":{"$date":"2023-09-20T10:28:51.488+05:30"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn2","msg":"Connection ended","attr":{"remote":"127.0.0.1:62675","uuid":{"uuid":{"$uuid":"8c007f81-c179-4164-8a42-b631ed789239"}},"connectionId":2,"connectionCount":0}}

Hey @Feel_The_Bits-DK_N_A,

Welcome to the MongoDB Community!

Could you attempt connecting to MongoDB after extending the serverSelectionTimeoutMS? Currently, if MongoDB fails to connect within the 2-second window, it triggers an error.

I suspect that there could be some other factors contributing to this issue. Could you check the mongod logs corresponding to the same timestamps? This additional information would help you in providing an understanding of the situation and identifying the root cause.

Please feel free to reach out in case of further questions.

Regards,
Kushagra

@Kushagra_Kesav I haven’t tried extending serverSelectionTimeoutMS, and when I hit command mongosh only two latest message appears in the log.

{"t":{"$date":"2023-09-20T10:28:51.485+05:30"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:62675","uuid":{"uuid":{"$uuid":"8c007f81-c179-4164-8a42-b631ed789239"}},"connectionId":2,"connectionCount":1}}
{"t":{"$date":"2023-09-20T10:28:51.488+05:30"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn2","msg":"Connection ended","attr":{"remote":"127.0.0.1:62675","uuid":{"uuid":{"$uuid":"8c007f81-c179-4164-8a42-b631ed789239"}},"connectionId":2,"connectionCount":0}}

@Kushagra_Kesav here is the log from same timestamp.

{"t":{"$date":"2023-09-20T16:39:05.425+05:30"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:59396","uuid":{"uuid":{"$uuid":"2c9780d9-bad9-401c-97e8-0b34c08d2abe"}},"connectionId":3,"connectionCount":1}}
{"t":{"$date":"2023-09-20T16:39:05.451+05:30"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn3","msg":"client metadata","attr":{"remote":"127.0.0.1:59396","client":"conn3","doc":{"application":{"name":"mongosh 1.10.6"},"driver":{"name":"nodejs|mongosh","version":"5.7.0|1.10.6"},"platform":"Node.js v16.20.2, LE","os":{"name":"win32","architecture":"x64","version":"10.0.19045","type":"Windows_NT"}}}}
{"t":{"$date":"2023-09-20T16:39:05.467+05:30"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:59397","uuid":{"uuid":{"$uuid":"01101a06-77f2-43d2-8167-997c9e7f392b"}},"connectionId":4,"connectionCount":2}}
{"t":{"$date":"2023-09-20T16:39:05.468+05:30"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:59398","uuid":{"uuid":{"$uuid":"d21e5a85-f04d-4f95-bb91-02c134e4af9a"}},"connectionId":5,"connectionCount":3}}
{"t":{"$date":"2023-09-20T16:39:05.469+05:30"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn4","msg":"client metadata","attr":{"remote":"127.0.0.1:59397","client":"conn4","doc":{"application":{"name":"mongosh 1.10.6"},"driver":{"name":"nodejs|mongosh","version":"5.7.0|1.10.6"},"platform":"Node.js v16.20.2, LE","os":{"name":"win32","architecture":"x64","version":"10.0.19045","type":"Windows_NT"}}}}
{"t":{"$date":"2023-09-20T16:39:05.470+05:30"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn5","msg":"client metadata","attr":{"remote":"127.0.0.1:59398","client":"conn5","doc":{"application":{"name":"mongosh 1.10.6"},"driver":{"name":"nodejs|mongosh","version":"5.7.0|1.10.6"},"platform":"Node.js v16.20.2, LE","os":{"name":"win32","architecture":"x64","version":"10.0.19045","type":"Windows_NT"}}}}
{"t":{"$date":"2023-09-20T16:39:05.473+05:30"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:59399","uuid":{"uuid":{"$uuid":"f6bdd65d-553d-44c3-b4a4-75068c7c5274"}},"connectionId":6,"connectionCount":4}}
{"t":{"$date":"2023-09-20T16:39:05.473+05:30"},"s":"I",  "c":"NETWORK",  "id":6788700, "ctx":"conn4","msg":"Received first command on ingress connection since session start or auth handshake","attr":{"elapsedMillis":3}}
{"t":{"$date":"2023-09-20T16:39:05.474+05:30"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn6","msg":"client metadata","attr":{"remote":"127.0.0.1:59399","client":"conn6","doc":{"application":{"name":"mongosh 1.10.6"},"driver":{"name":"nodejs|mongosh","version":"5.7.0|1.10.6"},"platform":"Node.js v16.20.2, LE","os":{"name":"win32","architecture":"x64","version":"10.0.19045","type":"Windows_NT"}}}}
{"t":{"$date":"2023-09-20T16:39:05.478+05:30"},"s":"I",  "c":"NETWORK",  "id":6788700, "ctx":"conn6","msg":"Received first command on ingress connection since session start or auth handshake","attr":{"elapsedMillis":3}}
{"t":{"$date":"2023-09-20T16:39:05.567+05:30"},"s":"I",  "c":"NETWORK",  "id":6788700, "ctx":"conn5","msg":"Received first command on ingress connection since session start or auth handshake","attr":{"elapsedMillis":97}}
{"t":{"$date":"2023-09-20T16:39:15.972+05:30"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:59406","uuid":{"uuid":{"$uuid":"fee6145c-0fbd-4630-b8e1-6de4347593ff"}},"connectionId":7,"connectionCount":5}}
{"t":{"$date":"2023-09-20T16:39:15.973+05:30"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn7","msg":"client metadata","attr":{"remote":"127.0.0.1:59406","client":"conn7","doc":{"application":{"name":"mongosh 1.10.6"},"driver":{"name":"nodejs|mongosh","version":"5.7.0|1.10.6"},"platform":"Node.js v16.20.2, LE","os":{"name":"win32","architecture":"x64","version":"10.0.19045","type":"Windows_NT"}}}}
{"t":{"$date":"2023-09-20T16:39:17.105+05:30"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn6","msg":"Connection ended","attr":{"remote":"127.0.0.1:59399","uuid":{"uuid":{"$uuid":"f6bdd65d-553d-44c3-b4a4-75068c7c5274"}},"connectionId":6,"connectionCount":4}}
{"t":{"$date":"2023-09-20T16:39:17.105+05:30"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn5","msg":"Connection ended","attr":{"remote":"127.0.0.1:59398","uuid":{"uuid":{"$uuid":"d21e5a85-f04d-4f95-bb91-02c134e4af9a"}},"connectionId":5,"connectionCount":3}}
{"t":{"$date":"2023-09-20T16:39:17.105+05:30"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn4","msg":"Connection ended","attr":{"remote":"127.0.0.1:59397","uuid":{"uuid":{"$uuid":"01101a06-77f2-43d2-8167-997c9e7f392b"}},"connectionId":4,"connectionCount":2}}
{"t":{"$date":"2023-09-20T16:39:17.105+05:30"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn7","msg":"Connection ended","attr":{"remote":"127.0.0.1:59406","uuid":{"uuid":{"$uuid":"fee6145c-0fbd-4630-b8e1-6de4347593ff"}},"connectionId":7,"connectionCount":1}}
{"t":{"$date":"2023-09-20T16:39:18.074+05:30"},"s":"W",  "c":"NETWORK",  "id":4615610, "ctx":"conn3","msg":"Failed to check socket connectivity","attr":{"error":{"code":6,"codeName":"HostUnreachable","errmsg":"peekASIOStream :: caused by :: Connection reset by peer"}}}
{"t":{"$date":"2023-09-20T16:39:18.074+05:30"},"s":"I",  "c":"-",        "id":20883,   "ctx":"conn3","msg":"Interrupted operation as its client disconnected","attr":{"opId":106841}}
{"t":{"$date":"2023-09-20T16:39:18.080+05:30"},"s":"I",  "c":"EXECUTOR", "id":22989,   "ctx":"conn3","msg":"Error sending response to client. Ending connection from remote","attr":{"error":{"code":6,"codeName":"HostUnreachable","errmsg":"futurize :: caused by :: Connection reset by peer"},"remote":"127.0.0.1:59396","connectionId":3}}
{"t":{"$date":"2023-09-20T16:39:18.080+05:30"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn3","msg":"Connection ended","attr":{"remote":"127.0.0.1:59396","uuid":{"uuid":{"$uuid":"2c9780d9-bad9-401c-97e8-0b34c08d2abe"}},"connectionId":3,"connectionCount":0}}
{"t":{"$date":"2023-09-20T16:39:28.401+05:30"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:59414","uuid":{"uuid":{"$uuid":"07bdefd9-f9cb-40f0-adff-0e0f592b492c"}},"connectionId":8,"connectionCount":1}}
{"t":{"$date":"2023-09-20T16:39:28.402+05:30"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn8","msg":"Connection ended","attr":{"remote":"127.0.0.1:59414","uuid":{"uuid":{"$uuid":"07bdefd9-f9cb-40f0-adff-0e0f592b492c"}},"connectionId":8,"connectionCount":0}}

can anyone suggest where it is going wrong?

i am not getting the solution, still i am trying to find out the solution, community can you please in this regard

try disabling your firewall

MongoDBCompass is getting connected this issue only occurring with mongosh command, i checked the windows defender firewall already disable

try upgrading mongosh, may be there is some tls certificate issue

1 Like