mongodb-js / vscode

Connect to MongoDB and Atlas and directly from your VS Code environment, navigate your databases and collections, inspect your schema and use playgrounds to prototype queries and aggregations.
https://marketplace.visualstudio.com/items?itemName=mongodb.mongodb-vscode
Apache License 2.0
326 stars 58 forks source link

Bug Report: unable to connect remote Replica Set connect unless proxy it on 127.0.0.1 #564

Closed Fallsleep closed 1 year ago

Fallsleep commented 1 year ago

Bug Report

Current Behavior

When I try to connect to the replica set mongodb in VirtulaBox,it come into Unable to connect: connect ECONNREFUSED 127.0.0.1:27017.

connect string: mongodb://homestead:secret@192.168.10.10:27017,192.168.10.10:27018,192.168.10.10:27019/?authSource=admin&replicaSet=rs0&readPreference=primary&ssl=false

after setting Port Forwarding rule in VirtulaBox, it connect well.

I guess there're some bugs with replica set connect code.

Code/Gist

Expected Behavior/Code

Environment

Possible Solution

Additional Context/Screenshots

harshita-2003 commented 1 year ago

Screenshot 2023-10-18 172138

I'm getting in mongodb compass ,how to resolve this though this is not a compass issue

addaleax commented 1 year ago

@Fallsleep Sorry, this went under our radar. You probably configured your replica sets to refer to each other using the 127.0.0.1 address, the client (regardless of which MongoDB client you are using) detects that and then tries to connect to that endpoint as well (because it doesn’t know that 127.0.0.1:27017 and 192.168.10.10:27017 refer to the same address).

You can either use directConnection=true to connect to a single host to work around this, or you could set up a mongos in front of the replica set and then connect to that.

@harshita-2003 Yeah, that’s probably a separate issue. Most likely, your MongoDB server is not actually running on port 27017; that’s what you’d want to check first.

harshita-2003 commented 1 year ago

It worked after start the mongodb from services , thankyou!

Fallsleep commented 1 year ago

Yes, I changed the replica set config to the virtual box host name instead of 127.0.0.1, and add the host name in hosts file, it can work well.