Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot connect to a replica set using 5.11.12 #9836

Closed
MihaiPerju opened this issue Jan 19, 2021 · 6 comments
Closed

Cannot connect to a replica set using 5.11.12 #9836

MihaiPerju opened this issue Jan 19, 2021 · 6 comments
Labels
help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary

Comments

@MihaiPerju
Copy link

MihaiPerju commented Jan 19, 2021

I am running my own MongoDb Replica Set on Kubernetes.

It has 3 members, I exposed them all via NodePort.

I can connect to it via shell:

(feel free to connect, it's an empty, isolated example that will be destroyed)

mongo mongodb://stackoverflow:[email protected]:31064,134.122.99.184:31086,134.122.99.184:32754/thirty3?authSource=admin

However, I cannot connect to it via mongoose 5.11.12 using the same connection string.
It only works until mongoose 4.5.8

mongoose.connect("mongodb://stackoverflow:[email protected]:31064,134.122.99.184:31086,134.122.99.184:32754/thirty3?authSource=admin&replicaSet=thirty3&?retryWrites=true&w=majority",
    {
      useNewUrlParser: true,
      poolSize: 5,
      useUnifiedTopology: true,
      serverSelectionTimeoutMS: 5000, // Timeout after 5s instead of 30s
    })

I tried tons of configurations, gssapiServiceName=mongodb, replicaSetName=thirty3 (I checked the replica set name by running rs.conf() ) and many more other configurations.

My question is - is there something wrong with mongoose handling these types of communications?

I have found similar issues that indicate downgrading as a solution, but downgrading is not ideal unless impossible to fix it normally.

Please try the code samples above, the database is open for connections with the credentials exposed.

@vkarpov15 vkarpov15 added this to the 5.11.14 milestone Jan 20, 2021
@vkarpov15
Copy link
Collaborator

My best guess is that this is a host name issue. I'll look into this some more, but I think that's the issue since the individual MongoDB servers think their hostname is something like thirty3-0.thirty3-svc.mongodb.svc.cluster.local:27017 rather than 134.122.99.184:32754

@MihaiPerju
Copy link
Author

@vkarpov15 thank you for your response.

That is a good point. I investigated it a lot since per their docs they say to provide replicaSetHorizons, in a following way:

security:
    tls:
      enabled: true
  connectivity:
    replicaSetHorizons:
      - "example-website": "web1.example.com:30907"
      - "example-website": "web2.example.com:32350"
      - "example-website": "web3.example.com:31185"

Now, I do have the external ports, I do have the IP, but it is not clear what specifically is the example-website and web[X].example.com needed to be replaced with.

I was curious since mongo shell command worked fine, so was the mongoose 4.5.8.

@vkarpov15 vkarpov15 added the help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary label Jan 20, 2021
@vkarpov15 vkarpov15 modified the milestones: 5.11.14, 5.11.15 Jan 28, 2021
@hungtcs
Copy link

hungtcs commented Feb 2, 2021

I may have encountered the same problem, v5.10.9 is working for me, but v5.11.14 I can not connect to my single node replica set.

@jooeycheng
Copy link
Contributor

@MihaiPerju Can you try appending ?directConnection=true to the Mongo URI?

@lucashpmelo
Copy link

@jooeycheng ?directConnection=true This works for me. Thank you!

mongoose v5.11.13

@vkarpov15
Copy link
Collaborator

I'm going to close this one since it looks like the servers are no longer available. As far as I can tell, this is an issue with replica set host names, you need to make sure that the host names in rs.conf() are the same ones as the ones in your connection string.

@vkarpov15 vkarpov15 removed this from the 5.11.17 milestone Feb 16, 2021
@Automattic Automattic locked and limited conversation to collaborators Feb 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
Projects
None yet
Development

No branches or pull requests

5 participants