renzholy / mongood

A MongoDB GUI with Fluent Design
GNU Affero General Public License v3.0
741 stars 58 forks source link

Connection Error. uri parser problem? #175

Open haoyun opened 2 years ago

haoyun commented 2 years ago

In the New Connection modal,

mongodb://username:password@mongo:27017

gives me

server selection error: server selection timeout, current topology: {
Type: ReplicaSetNoPrimary,
Servers: [{ 
  Addr: localhost:27017, 
  Type: Unknown, 
  Last error: connection() error occured during connection handshake: dial tcp [::1]:27017: connect: connection refused
},]
}

The host in the error message is clearly incorrect.

However,

mongodb://username:password@mongo:2701

gives

server selection error: server selection timeout, current topology: { 
Type: Unknown, 
Servers: [{ 
  Addr: mongo:2701,
  Type: Unknown, 
  Last error: connection() error occured during connection handshake: dial tcp 10.88.2.4:2701: connect: connection refused 
}, ] 
}

This time the host is correct, but that's not the address I need.

I tried

mongodb://username:password@10.88.2.4:27017

The error message is the same as the first one.

BTW, I am running mongood and mongo via docker-compose. I can confirm that the hostname mongo (corresponds to IP 10.88.2.4) can be resolved from the mongood container.

Moreover, from the devtools in the browser, I can see that the payload send to http://localhost:3000/api/runCommand?d=admin&c=ping is always correct.

haoyun commented 2 years ago

I solve this problem by passing in the following address:

mongodb://username:password@mongo:27017?directConnection=true&serverSelectionTimeoutMS=2000

as pointed out here.