seatunnel icon indicating copy to clipboard operation
seatunnel copied to clipboard

[bug][connector-cdc-mongodb] Fails to Connect to MongoDB Atlas Due to Hardcoded URI Scheme "mongodb://"

Open starrysky9959 opened this issue 2 weeks ago • 3 comments

Issue Description

When attempting to use the SeaTunnel MongoDB CDC Connector as a source for data extraction from a MongoDB Atlas cluster, the connection fails because the connector does not support the recommended DNS Seed List URI format: mongodb+srv://.

Upon investigating the connector's source code, I found that the connection URI is being hardcoded with the scheme mongodb://.

https://github.com/apache/seatunnel/blob/349841e8d2bde06dd42b56b07704765dad230e9c/seatunnel-connectors-v2/connector-cdc/connector-cdc-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/mongodb/utils/MongodbUtils.java#L385

Expected Behavior

The MongoDB CDC Connector should fully support the standard connection URI formats provided by MongoDB drivers, including the DNS Seed List format, for the following reasons:

Steps to Reproduce

  1. Obtain the Standard Connection String for a MongoDB Atlas cluster (it will be in the format mongodb+srv://...).
  2. Configure a SeaTunnel MongoDB CDC Connector source using this mongodb+srv:// URI.
  3. Attempt to run the SeaTunnel job.
  4. Result: The job fails immediately due to an illegal URI scheme or parsing error because the code expects the URI to start with mongodb://.

Suggested Fix

The connector's logic for constructing the connection URI should be modified to:

  1. Accept the full user-provided URI without overriding or prepending the scheme (mongodb://).
  2. Ensure the underlying MongoDB Java driver can correctly parse and handle both mongodb:// and mongodb+srv:// schemes.

starrysky9959 avatar Dec 09 '25 15:12 starrysky9959

It's good. Adding a parameter to enable DNS SRV for switching between these two connection protocols, how about that?

Cyanty avatar Dec 10 '25 17:12 Cyanty

The MongoDB driver itself natively supports both mongodb:// (standard connection) and mongodb+srv:// (DNS SRV connection) protocols. The driver automatically switches between them by simply checking the URI prefix. For instance, the SeaTunnel MongoDB connector (non-CDC) seems to implement this correctly by using a single uri parameter.

Therefore, the most natural and standard approach would be to have the user specify a complete connection URI (e.g., mongodb://... or mongodb+srv://...). The connector should then pass this full URI directly to the MongoDB driver for connection, eliminating the need for an additional, redundant parameter to enable/disable DNS SRV. Allowing the user to provide the complete URI (including the protocol scheme) ensures we leverage the driver's native functionality.

starrysky9959 avatar Dec 10 '25 17:12 starrysky9959

The MongoDB driver itself natively supports both mongodb:// (standard connection) and mongodb+srv:// (DNS SRV connection) protocols. The driver automatically switches between them by simply checking the URI prefix. For instance, the SeaTunnel MongoDB connector (non-CDC) seems to implement this correctly by using a single uri parameter.

Therefore, the most natural and standard approach would be to have the user specify a complete connection URI (e.g., mongodb://... or mongodb+srv://...). The connector should then pass this full URI directly to the MongoDB driver for connection, eliminating the need for an additional, redundant parameter to enable/disable DNS SRV. Allowing the user to provide the complete URI (including the protocol scheme) ensures we leverage the driver's native functionality.

Got it, that's fine. If you have time, you can open a PR to solve it.

P.S. Taking into account the compatibility between different versions, the old configuration method should also be retained.

Cyanty avatar Dec 10 '25 17:12 Cyanty