Error: connecting with MongoDB

Hello everyone !

I need help, I’m facing the following error.

If someone could help me, I will be very happy, I’m trying for 4 days and just got “no positive results”.

PS C:\Users\Victor Davi\Desktop\node\banco> node index.js  
C:\Users\Victor Davi\Desktop\node\banco\node_modules\mongodb\lib\utils.js:417
                    throw error;
                    ^

MongoServerSelectionError: Hostname/IP does not match certificate's altnames: Host: cluster0-shard-00-00.zberv.mongodb.net. is not in the cert's altnames: DNS:*.mongodb.net, DNS:mongodb.net
    at Timeout._onTimeout (C:\Users\Victor Davi\Desktop\node\banco\node_modules\mongodb\lib\sdam\topology.js:318:38)  
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7) {        
  reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    servers: Map(3) {
      'cluster0-shard-00-00.zberv.mongodb.net:27017' => ServerDescription {
        _hostAddress: HostAddress {
          isIPv6: false,

CODE*

'use strict';

const mongodb = require('mongodb').MongoClient;

const url = "mongodb+srv://<user>:<pwd>@cluster0.zberv.mongodb.net/test?retryWrites=true&w=majority";

mongodb.connect(url,(erro,banco)=>{

    if(erro)throw erro;

    const dbo= banco.db("test");//Documento do banco de dados

    const obj = {curso: "Curso de Node", canal: "CFB Cursos"};//Dados que serão armazenados dentro do banco de dados

    const colecao = "cursos";

    dbo.collection(colecao).insertOne(obj,(erro,resultado)=>{

        if(erro)throw erro;

        console.log("1 novo curso inserido");

        banco.close();

    });

});

Can you connect by shell using your SRV string?
I tried both SRV and long form string but neither worked
Can you check status of your cluster in Atlas

Hi @Victor_Davi_Almeida - Welcome to the community!

To further assist the troubleshooting here, could you provide the following information:

  1. The Atlas cluster tier
  2. The MongoDB version
  3. The Driver being used to connect
  4. The Driver version
  5. If you are able to connect to the cluster via mongosh or MongoDB Compass
  6. Any errors or output from connectivity failures from 5

Regards,
Jason

3 Likes

Hello @Jason_Tran

Thank you for having me !

  1. The Atlas cluster tier : M0 Sandbox (General)
  2. The MongoDB version: ^4.5.0
  3. The Driver being used to connect: node.js
  4. The Driver version: v16.4.2
  5. If you are able to connect to the cluster via [ mongosh ]: NOTE: I didn’t tried this yet.(https://www.mongodb.com/docs/mongodb-shell/) or [MongoDB Compass]
  6. Any errors or output from connectivity failures from 5
    Error: MongoServerSelectionError: Hostname/IP does not match certificate’s altnames: Host: cluster0-shard-00-00.zberv.mongodb.net. is not in the cert’s altnames: DNS:*.mongodb.net, DNS:mongodb.net

Can be some problem with my firewall ? Do you have some other code to I use in order to test ?

1 Like

Thanks for providing that information @Victor_Davi_Almeida!

Can be some problem with my firewall ? Do you have some other code to I use in order to test ?

At this stage it’s difficult to say for certain what the issue could be. However, there is an example on the MongoDB Node.JS driver quick start page.

MongoServerSelectionError: Hostname/IP does not match certificate’s altnames: Host: cluster0-shard-00-00.zberv.mongodb.net. is not in the cert’s altnames: DNS:*.mongodb.net, DNS:mongodb.net

I believe the issue may be related to certificates just based off this error but it would be good to test if you are able to connect via MongoDB Compass for troubleshooting purposes from the same client that’s receiving this error upon connection.

In saying so, can you attempt to connect via MongoDB Compass from the same client and let me know if you are able to connect?

Regards,
Jason

2 Likes

Both Compass & Shell failing to connect
Could it be with whitelist IP?
May be allow access from anywhere temporarily and check the connection
Then figure out if it is firewall or some other issue

1 Like

I think its some problem related with IP, but i dont know why.
First. Could you tell me what is the whitelist IP ?
I’ve allowed access to anywhere IP and tried to connect, I’ve got the same error.

I’ve performed the Node.JS driver quick start page - I’ve got the same error.
In compass, I’ve got the same error.

1 Like

I think its some problem related with IP, but i dont know why.
I’ve allowed access to anywhere IP and tried to connect, I’ve got the same error.
I’ve performed the Node.JS driver quick start page - I’ve got the same error.
In compass, I’ve got the same error.
In compass, I switched to access just one host of the cluster, no success too.
It seems the Host name is mismatching.

Jason, Do I need to have an account in Amazon ? I’m only signing in the Mongo Atlas.
I’m thinking about deleting the cluster and create a new one.

1 Like

Hi @Victor_Davi_Almeida,

First. Could you tell me what is the whitelist IP ?

I believe Ramachandra was referring to the Atlas Network Access List. However, please feel to correct me if i’m wrong here Ramachandra :slight_smile:

I’ve performed the Node.JS driver quick start page - I’ve got the same error.
In compass, I’ve got the same error.

Thank you for confirming - Could you provide the following information:

  • Operating System in use
  • Operating System version
  • If connecting with the standard connection string (where it begins with mongodb:// instead of mongodb+srv://) works or provides the same error? You may find some detailed steps in this post here for retrieving the standard connection string for the Node.JS driver

The MongoDB Compass utilises the Node.JS driver so it was not surprising to see the same error.

Jason, Do I need to have an account in Amazon ? I’m only signing in the Mongo Atlas.

If you are referring to having an amazon account for resolving this error - No.

Regards,
Jason

Yes i meant that
Before you drop and recreate your cluster show us your Atlas cluster details/status
Can you see your DBs/collections?

The whilelist already has the IP from my computer, I’ve got it by using " ipconfig" in the cmd terminal.

  • Operating System in use : Windowns
  • Operating System version: 10
  • If connecting with the [standard connection string
    I tried by using mongodbcompass and the following string
    mongodb://teste:teste@cluster0-shard-00-02.zberv.mongodb.net:27017/?authSource=admin&replicaSet=myRepl&tls=true
    But I’ve got this alarm.
    Server selection timed out after 30000 ms

See Unable to connect to Atlas cluster using "Standard Connection String" format - #2 by steevej

Did you try with SRV string again?
I can connect
What has changed from previous to now?

MongoDB Enterprise atlas-bay1mf-shard-0:PRIMARY> db
test
MongoDB Enterprise atlas-bay1mf-shard-0:PRIMARY> show dbs
admin 0.000GB
local 1.059GB
MongoDB Enterprise atlas-bay1mf-shard-0:PRIMARY> exit
bye

Bro, I’ve deleted the previous cluster0 and created a new one.
The old one had a AWS cloud.
This has a Google cloud.
This hasn’t sample data base.

Other question, Did you connected with the string I provided in the last answer ?
mongodb://teste:teste@cluster0-shard-00-02.zberv.mongodb.net:27017/?authSource=admin&replicaSet=myRepl&tls=true
If yes, I have a question, The following directory below, I don’t have access to it:
MongoDB Enterprise atlas-bay1mf-shard-0:PRIMARY> db
test
What just appeared to my Atlas are:
cluster0-shard-00-02.zberv.mongodb.net:27017 (Primary)
and the “similars” (Secondary)
Did you change this name ? atlas-bay1mf-shard-0:PRIMARY>
How do I visualize this name in Atlas ?
I need to put this name in my string connection, such as the example below ?
mongodb://teste:teste@cluster0- atlas-bay1mf-shard-0shard-00-02.zberv.mongodb.net:27017/?authSource=admin&replicaSet=myRepl&tls=true

No I did not use your connect string
I used SRV string format
Why do you want to connect by giving primary or secondary name?
Use SRV string which uses clustername and it automatically connected to primary without using any replset name
Did you try what Steeve shared I,e long form of string which uses all 3 node names?
From Atlas when you choose connect by shell it will give you connect string SRV or long form depending on shell version you select
Also from DIG command you can find out name of replset
Check our forum threads

I have serious doubts about that.

I would be very surprised that you terminated the cluster cluster0.zberv.mongodb.net and that Atlas provided you with a new cluster with the same name as the cluster you mentioned on your first post on April 27. But I might be wrong, because after all, saru mo ki kara ochiru.

Further more, since I also

and the following rs.status() information

   lastElectionReason: 'stepUpRequestSkipDryRun',
   lastElectionDate: 2022-04-26T14:16:21.658Z,

indicates that the cluster you mentioned on April 27 is still up and running since the 26th.

So, I am also interested to know

The following will not work. Your replica set is NOT named myRepl.

It is named atlas-bay1mf-shard-0.

Hello Steevej

saru mo ki kara ochiru . In portuguese “Macaco também cai do avião”, I don’t know exactly what this means in japanese, but I like it :smiley: !

I’ll try to connect with this name : atlas-bay1mf-shard-0 .
My question is, How I can identify the name ?
Because the name that appears to me is different.
Probably I don’t know how to check it, Can you please tell me how I do it ?

Thanks and 後になるまで (I believe its goodbye)

1 Like

I’ll check the Forum Threads soon as possible.

Thank you for the help you gave me until know bro.

The correct world would be Árvore rather than avião.

For Even monkeys fall from trees. I use that when I completely screw up (to say: sorry I made a mistake, the monkey is me and I just fall from a tree) or when I assert something I am not 100% sure.

I am sure that you should not:

Use the Connect button from your Atlas cluster and try to use the SRV version. Otherwise specify an older version of the shell and connect using the old way.

As for

it is a little bit tricky. I cannot really explain better than SRV record - Wikipedia.

My mother tongue is French so I do not know about