[bug][connector-cdc-mongodb] Fails to Connect to MongoDB Atlas Due to Hardcoded URI Scheme "mongodb://"
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
- Obtain the Standard Connection String for a MongoDB Atlas cluster (it will be in the format
mongodb+srv://...). - Configure a SeaTunnel MongoDB CDC Connector source using this
mongodb+srv://URI. - Attempt to run the SeaTunnel job.
- 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:
- Accept the full user-provided URI without overriding or prepending the scheme (
mongodb://). - Ensure the underlying MongoDB Java driver can correctly parse and handle both
mongodb://andmongodb+srv://schemes.
It's good. Adding a parameter to enable DNS SRV for switching between these two connection protocols, how about that?
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.
The MongoDB driver itself natively supports both
mongodb://(standard connection) andmongodb+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 singleuriparameter.Therefore, the most natural and standard approach would be to have the user specify a complete connection URI (e.g.,
mongodb://...ormongodb+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.