Add directConnection support for MongoDB #123

Closed
opened 2026-04-05 16:15:48 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @Ujstor on 2/18/2026

Problem

When connecting to a MongoDB replica set member exposed via a Kubernetes LoadBalancer (e.g. using replicaSetHorizons with the MongoDB Operator), Databasus fails with:

server selection error: context deadline exceeded, current topology: { Type: ReplicaSetNoPrimary, Servers: [{ Addr: press-check-mongo-pck-0.press-check-mongo-pck-svc.press-check.svc.cluster.local:27017, Type: Unknown, Last error: dial tcp: lookup press-check-mongo-pck-0.press-check-mongo-pck-svc.press-check.svc.cluster.local on 10.254.0.10:53: no such host }, ] }

Root cause: MongoDB replica set discovery returns internal Kubernetes FQDNs to external clients. The replicaSetHorizons feature requires TLS+SNI . The MongoDB driver parameter directConnection=true bypasses topology discovery entirely, solving this issue.

Currently there is no way to pass directConnection=true (or any extra connection string parameters) through the Databasus UI or data model.

Proposed Solution

Add a directConnection boolean toggle to the MongoDB connection settings under Advanced settings, alongside the existing "Use SRV connection" option.

When enabled, append &directConnection=true to the connection URI in both buildConnectionURI() and BuildMongodumpURI().

Use Cases

  • Connecting to a single-member MongoDB replica set exposed via LoadBalancer/NodePort
  • Connecting to MongoDB behind a reverse proxy or SSH tunnel
  • Any environment where replica set topology discovery returns unreachable addresses
*Originally created by @Ujstor on 2/18/2026* ### Problem When connecting to a MongoDB replica set member exposed via a Kubernetes LoadBalancer (e.g. using `replicaSetHorizons` with the MongoDB Operator), Databasus fails with: ``` server selection error: context deadline exceeded, current topology: { Type: ReplicaSetNoPrimary, Servers: [{ Addr: press-check-mongo-pck-0.press-check-mongo-pck-svc.press-check.svc.cluster.local:27017, Type: Unknown, Last error: dial tcp: lookup press-check-mongo-pck-0.press-check-mongo-pck-svc.press-check.svc.cluster.local on 10.254.0.10:53: no such host }, ] } ``` **Root cause:** MongoDB replica set discovery returns internal Kubernetes FQDNs to external clients. The `replicaSetHorizons` feature requires TLS+SNI . The MongoDB driver parameter [`directConnection=true`](https://www.mongodb.com/docs/manual/reference/connection-string/#mongodb-urioption-urioption.directConnection) bypasses topology discovery entirely, solving this issue. Currently there is no way to pass `directConnection=true` (or any extra connection string parameters) through the Databasus UI or data model. ### Proposed Solution Add a `directConnection` boolean toggle to the MongoDB connection settings under **Advanced settings**, alongside the existing "Use SRV connection" option. When enabled, append `&directConnection=true` to the connection URI in both `buildConnectionURI()` and `BuildMongodumpURI()`. ### Use Cases - Connecting to a single-member MongoDB replica set exposed via LoadBalancer/NodePort - Connecting to MongoDB behind a reverse proxy or SSH tunnel - Any environment where replica set topology discovery returns unreachable addresses
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/databasus#123