Improve mongosh connection time
![](https://secure.gravatar.com/avatar/c8ec09dec7182f23723c0ec36912a661?size=40&default=https%3A%2F%2Fassets.uvcdn.com%2Fpkg%2Fadmin%2Ficons%2Fuser_70-6bcf9e08938533adb9bac95c3e487cb2a6d4a32f890ca6fdc82e3072e0ea0368.png)
-
Wernfried commented
How fast do you like to have it?
time mongosh "mongodb://user:password@localhost/?authSource=admin" --quiet --eval "db.getMongo()"
mongodb://<credentials>@localhost/?authSource=admin&directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.6.0real 0m1.288s
user 0m1.457s
sys 0m0.118s1.5 seconds sounds not bad to me.
Actual connection time is even shorter (around 150 milliseconds) as you can see in the logs:
$ cat .mongodb/mongosh/63490dd8851dfcff3400c83c_log
{"t":{"$date":"2022-10-14T07:20:56.081Z"},"s":"I","c":"MONGOSH","id":1000000000,"ctx":"log","msg":"Starting log" ...
{"t":{"$date":"2022-10-14T07:20:56.084Z"},"s":"I","c":"MONGOSH","id":1000000005,"ctx":"config","msg":"User updated"}
{"t":{"$date":"2022-10-14T07:20:56.085Z"},"s":"I","c":"MONGOSH","id":1000000048,"ctx":"config","msg":"Loading global configuration file"...
{"t":{"$date":"2022-10-14T07:20:56.133Z"},"s":"I","c":"DEVTOOLS-CONNECT","id":1000000042,"ctx":"mongosh-connect","msg":"Initiating connection attempt",...
{"t":{"$date":"2022-10-14T07:20:56.148Z"},"s":"I","c":"DEVTOOLS-CONNECT","id":1000000035,"ctx":"mongosh-connect","msg":"Server heartbeat succeeded",...
{"t":{"$date":"2022-10-14T07:20:56.183Z"},"s":"I","c":"DEVTOOLS-CONNECT","id":1000000037,"ctx":"mongosh-connect","msg":"Connection attempt finished"}
{"t":{"$date":"2022-10-14T07:20:56.228Z"},"s":"I","c":"MONGOSH","id":1000000004,"ctx":"connect","msg":"Connecting to server"