I guess my searching is bad I see that option for the golang mongodriver too: options package - go.mongodb.org/mongo-driver/mongo/options - Go Packages
I’m thinking the names in your replicaset are not resolvable/reachable from the vault server. Which is one reason why I have asked “Can you connect from the same host where vault is using mongosh ?”, I should have further specified “with the same connection string”.
The names you see from db.hello().hosts
is what the driver will use for the replicaset, allowing it to connect to the next primary if the current one fails or steps down. The hosts you define in a connection string are seed hosts, hosts that the driver can connect to and discover the replica set.
In the case of direct, the driver is connecting only to one host.
Vault’s -log-level trace
option will show the problems it is encountering.
An example when names in the replcaset are not resolvable.
Vault’s (v1.8.2) pop up error:
There was a verification error for this connection. Check the Vault logs for more information.
Trace Log:
2021-09-15T14:20:33.334-0400 [TRACE] secrets.database.database_cd8797eb.mongodb-database-plugin: initialize: transport=builtin status=finished verify=true err=“failed to verify connection: server selection error: server selection timeout, current topology: { Type: ReplicaSetNoPrimary, Servers: [{ Addr: 0b8a7bf72092:27017, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection() : dial tcp: lookup 0b8a7bf72092 on 192.168.1.254:53: no such host }, { Addr: f0aa1ac332d7:27017, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection() : dial tcp: lookup f0aa1ac332d7 on 192.168.1.254:53: no such host }, { Addr: 19f3bb7a0948:27017, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection() : dial tcp: lookup 19f3bb7a0948 on 192.168.1.254:53: no such host }, ] }” took=4.001731259s