I’m learning MongoDB and set up an Atlas account. I’m trying to connect to my database using mongosh, allowed all IPs, set up my user and password credentials but I’m getting an error:
MongoServerSelectionError: Hostname/IP does not match certificate's altnames: Host: ac-kiiemsq-shard-00-00.cbhjwlv.mongodb.net. is not in the cert's altnames: DNS:*.mongodb.net, DNS:mongodb.net
Upon checking my logs, this is what shows:
{"t":{"$date":"2023-02-15T10:21:27.465Z"},"s":"I","c":"MONGOSH","id":1000000000,"ctx":"log","msg":"Starting log","attr":{"execPath":"/opt/homebrew/Cellar/node/19.6.0/bin/node","envInfo":{"EDITOR":null,"NODE_OPTIONS":null,"TERM":"xterm-256color"},"version":"1.7.1","distributionKind":"packaged","buildArch":"x64","buildPlatform":"linux","buildTarget":"unknown","buildTime":"2023-02-13T19:19:00.135Z","gitVersion":"1bf0d7775443ac1849cc2597465d54eca867acea","nodeVersion":"v19.6.0","opensslVersion":"1.1.1s","sharedOpenssl":true}}
{"t":{"$date":"2023-02-15T10:21:27.469Z"},"s":"I","c":"MONGOSH","id":1000000005,"ctx":"config","msg":"User updated"}
{"t":{"$date":"2023-02-15T10:21:27.470Z"},"s":"I","c":"MONGOSH","id":1000000048,"ctx":"config","msg":"Loading global configuration file","attr":{"filename":"/etc/mongosh.conf","found":false}}
{"t":{"$date":"2023-02-15T10:21:27.475Z"},"s":"E","c":"DEVTOOLS-CONNECT","id":1000000041,"ctx":"mongosh-deps","msg":"Missing optional dependency","attr":{"name":"mongodb-client-encryption","error":"Cannot find module 'mongodb-client-encryption'\nRequire stack:\n- /opt/homebrew/Cellar/mongosh/1.7.1/libexec/lib/node_modules/@mongosh/cli-repl/node_modules/@mongodb-js/devtools-connect/lib/connect.js\n- /opt/homebrew/Cellar/mongosh/1.7.1/libexec/lib/node_modules/@mongosh/cli-repl/node_modules/@mongodb-js/devtools-connect/lib/index.js\n- /opt/homebrew/Cellar/mongosh/1.7.1/libexec/lib/node_modules/@mongosh/cli-repl/node_modules/@mongosh/service-provider-server/lib/cli-service-provider.js\n- /opt/homebrew/Cellar/mongosh/1.7.1/libexec/lib/node_modules/@mongosh/cli-repl/node_modules/@mongosh/service-provider-server/lib/index.js\n- /opt/homebrew/Cellar/mongosh/1.7.1/libexec/lib/node_modules/@mongosh/cli-repl/lib/cli-repl.js\n- /opt/homebrew/Cellar/mongosh/1.7.1/libexec/lib/node_modules/@mongosh/cli-repl/lib/index.js\n- /opt/homebrew/Cellar/mongosh/1.7.1/libexec/lib/node_modules/@mongosh/cli-repl/lib/run.js\n- /opt/homebrew/Cellar/mongosh/1.7.1/libexec/lib/node_modules/@mongosh/cli-repl/bin/mongosh.js"}}
{"t":{"$date":"2023-02-15T10:21:27.517Z"},"s":"I","c":"DEVTOOLS-CONNECT","id":1000000039,"ctx":"mongosh-connect","msg":"Resolving SRV record succeeded","attr":{"from":"mongodb+srv://<credentials>@cluster0.cbhjwlv.mongodb.net/myFirstDatabase?appName=mongosh+1.7.1","to":"mongodb://<credentials>@ac-kiiemsq-shard-00-00.cbhjwlv.mongodb.net,ac-kiiemsq-shard-00-01.cbhjwlv.mongodb.net,ac-kiiemsq-shard-00-02.cbhjwlv.mongodb.net/myFirstDatabase?appName=mongosh+1.7.1&authSource=admin&replicaSet=atlas-142s5d-shard-0&tls=true","resolutionDetails":[{"query":"SRV","hostname":"_mongodb._tcp.cluster0.cbhjwlv.mongodb.net","error":null,"wasNativelyLookedUp":true},{"query":"TXT","hostname":"cluster0.cbhjwlv.mongodb.net","error":null,"wasNativelyLookedUp":true}]}}
{"t":{"$date":"2023-02-15T10:21:27.530Z"},"s":"I","c":"DEVTOOLS-CONNECT","id":1000000042,"ctx":"mongosh-connect","msg":"Initiating connection attempt","attr":{"uri":"mongodb://<credentials>@ac-kiiemsq-shard-00-00.cbhjwlv.mongodb.net,ac-kiiemsq-shard-00-01.cbhjwlv.mongodb.net,ac-kiiemsq-shard-00-02.cbhjwlv.mongodb.net/myFirstDatabase?appName=mongosh+1.7.1&authSource=admin&replicaSet=atlas-142s5d-shard-0&tls=true","driver":{"name":"nodejs|mongosh","version":"4.14.0"},"devtoolsConnectVersion":"1.4.4","host":"ac-kiiemsq-shard-00-00.cbhjwlv.mongodb.net:27017,ac-kiiemsq-shard-00-01.cbhjwlv.mongodb.net:27017,ac-kiiemsq-shard-00-02.cbhjwlv.mongodb.net:27017"}}
{"t":{"$date":"2023-02-15T10:21:27.867Z"},"s":"W","c":"DEVTOOLS-CONNECT","id":1000000034,"ctx":"mongosh-connect","msg":"Server heartbeat failure","attr":{"connectionId":"ac-kiiemsq-shard-00-02.cbhjwlv.mongodb.net:27017","failure":"","isFailFast":false,"isKnownServer":true}}
{"t":{"$date":"2023-02-15T10:21:28.053Z"},"s":"W","c":"DEVTOOLS-CONNECT","id":1000000034,"ctx":"mongosh-connect","msg":"Server heartbeat failure","attr":{"connectionId":"ac-kiiemsq-shard-00-01.cbhjwlv.mongodb.net:27017","failure":"Hostname/IP does not match certificate's altnames: Host: ac-kiiemsq-shard-00-01.cbhjwlv.mongodb.net. is not in the cert's altnames: DNS:*.mongodb.net, DNS:mongodb.net","isFailFast":false,"isKnownServer":true}}
{"t":{"$date":"2023-02-15T10:21:28.200Z"},"s":"W","c":"DEVTOOLS-CONNECT","id":1000000034,"ctx":"mongosh-connect","msg":"Server heartbeat failure","attr":{"connectionId":"ac-kiiemsq-shard-00-00.cbhjwlv.mongodb.net:27017","failure":"Hostname/IP does not match certificate's altnames: Host: ac-kiiemsq-shard-00-00.cbhjwlv.mongodb.net. is not in the cert's altnames: DNS:*.mongodb.net, DNS:mongodb.net","isFailFast":false,"isKnownServer":true}}
I’ve tried connecting through Mongodb Compass and the connection is successful. I'm using a Mac with mongoDB and Mongosh installed through brew, all updated to the latest version.
If you downgrade your version of mongosh to 1.6.2, you will be able to connect.
brew uninstall mongodb-community
brew uninstall mongosh
wget https://raw.githubusercontent.com/Homebrew/homebrew-core/4519776bc4563548dcd8c8639ac7e073b107c381/Formula/mongosh.rb
brew install ./mongosh.rb