Skip to content

chore(deps): Upgrading mongodb driver to mongodb driver sync#27685

Open
josephglerin wants to merge 1 commit intoprestodb:masterfrom
josephglerin:mongodb-driver-upgrade
Open

chore(deps): Upgrading mongodb driver to mongodb driver sync#27685
josephglerin wants to merge 1 commit intoprestodb:masterfrom
josephglerin:mongodb-driver-upgrade

Conversation

@josephglerin
Copy link
Copy Markdown

@josephglerin josephglerin commented Apr 29, 2026

Upgrade MongoDB driver from mongodb-driver-legacy to mongodb-driver-sync

Upgrade Presto MongoDB connector from the unmaintained legacy MongoDB Java driver to the modern MongoDB Java Driver Sync (version 5.6.5)

Motivation and Context

The Presto MongoDB connector currently uses the legacy MongoDB Java driver, which MongoDB officially deprecated and no longer maintains. This upgrade is critical for several reasons:

  1. End of Life & Security

    • The legacy driver reached end-of-life and receives no security patches or bug fixes
    • Continued use exposes Presto deployments to unpatched vulnerabilities
    • Modern driver receives active security updates and maintenance
  2. MongoDB Server Compatibility

    • Legacy driver cannot leverage features introduced in MongoDB 3.0+ (released 2015)
    • Missing support for modern MongoDB capabilities like:
  3. Performance & Reliability

    • Modern driver includes significant performance optimizations
    • Better connection management and automatic failover
  4. Future-Proofing

    • Ensures compatibility with current and future MongoDB server versions
    • Aligns with MongoDB's supported driver ecosystem
    • Enables adoption of new MongoDB features as they're released

Reference: MongoDB Legacy Driver Documentation

Impact

Test Plan

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.
  • If adding new dependencies, verified they have an OpenSSF Scorecard score of 5.0 or higher (or obtained explicit TSC approval for lower scores).

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== RELEASE NOTES ==

MongoDB Connector Changes
* Upgrade mongo-java-driver to mongodb-driver-sync

Summary by Sourcery

Upgrade the MongoDB connector to use the modern mongodb-driver-sync client and configuration APIs.

Enhancements:

  • Refactor MongoClient creation to use MongoClientSettings, ConnectionString-based configuration, and MongoClients.create with support for read preferences, TLS, and replica set discovery.
  • Simplify write concern handling by dropping deprecated WriteConcernType values no longer supported by the updated driver.

Build:

  • Upgrade MongoDB Java driver to version 5.6.5 and switch the dependency from mongo-java-driver to mongodb-driver-sync, adding explicit mongodb-driver-core and bson dependencies.

Tests:

  • Update MongoDB TLS, integration, and query runner tests to construct clients via MongoClientSettings and MongoClients.create, aligning with the new driver APIs.

@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Apr 29, 2026
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Apr 29, 2026

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: josephglerin / name: josephglerin (197d3d2)

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 29, 2026

Reviewer's Guide

Upgrades the Presto MongoDB connector from the legacy Mongo client to the modern mongodb-driver-sync API, refactoring client/session construction, TLS/read preference handling, and tests to use MongoClientSettings and connection strings, and updating driver dependencies and supported write concerns accordingly.

Sequence diagram for MongoSession creation with MongoClientSettings and connection string

sequenceDiagram
    participant Caller as MongoClientModule_createMongoSession_caller
    participant MCM as MongoClientModule
    participant MCSB as MongoClientSettings_Builder
    participant CSP as ConnectionStringParser
    participant MCP as MongoClientPoolSettings
    participant MSS as MongoSocketSettings
    participant SSL as SslContextProvider
    participant MC as MongoClient

    Caller->>MCM: createMongoSession(typeManager, mongoClientConfig)
    activate MCM
    MCM->>MCM: buildConnectionString(mongoClientConfig)
    activate MCM
    MCM->>CSP: new ConnectionString(connectionString)
    deactivate MCM
    MCM->>MCSB: MongoClientSettings.builder()
    activate MCSB
    MCM->>MCSB: applyConnectionString(connectionString)

    MCM->>MCSB: applyToConnectionPoolSettings(maxSize, minSize, maxWaitTime)
    activate MCP
    MCP-->>MCSB: configuredPoolSettings
    deactivate MCP

    MCM->>MCSB: applyToSocketSettings(connectTimeout, readTimeout)
    activate MSS
    MSS-->>MCSB: configuredSocketSettings
    deactivate MSS

    MCM->>MCM: configureReadPreference(mongoClientConfig)
    MCM-->>MCSB: readPreference

    MCM->>MCSB: writeConcern(writeConcernFromConfig)

    alt replicaSetNamePresent
        MCM->>MCSB: applyToClusterSettings(requiredReplicaSetName)
    end

    alt tlsEnabled
        MCM->>SSL: new SslContextProvider(truststorePath, truststorePassword, keystorePath, keystorePassword)
        activate SSL
        SSL-->>MCM: buildSslContext_optional
        deactivate SSL
        MCM->>MCSB: applyToSslSettings(enabled=true, context=sslContext)
    end

    MCSB-->>MCM: MongoClientSettings
    deactivate MCSB

    MCM->>MC: MongoClients.create(settings)
    activate MC

    MCM-->>Caller: new MongoSession(typeManager, MC, mongoClientConfig)
    deactivate MC
    deactivate MCM
Loading

Class diagram for updated MongoClientModule and WriteConcernType

classDiagram
    class MongoClientModule {
        +MongoClientModule()
        +static MongoSession createMongoSession(TypeManager typeManager, MongoClientConfig config)
        -static String buildConnectionString(MongoClientConfig config)
        -static ReadPreference configureReadPreference(MongoClientConfig config)
        -static void configureSsl(MongoClientSettings_Builder settings, MongoClientConfig config)
    }

    class MongoClientConfig {
        +List~ServerAddress~ getSeeds()
        +List~MongoCredential~ getCredentials()
        +int getConnectionsPerHost()
        +int getMinConnectionsPerHost()
        +int getMaxWaitTime()
        +int getConnectionTimeout()
        +int getSocketTimeout()
        +boolean getSocketKeepAlive()
        +WriteConcernType getWriteConcern()
        +MongoReadPreferenceType getReadPreference()
        +List~TagSet~ getReadPreferenceTags()
        +String getRequiredReplicaSetName()
        +boolean isTlsEnabled()
        +String getTruststorePath()
        +String getTruststorePassword()
        +String getKeystorePath()
        +String getKeystorePassword()
    }

    class MongoSession {
        +MongoSession(TypeManager typeManager, MongoClient client, MongoClientConfig config)
        +void shutdown()
        +MongoDatabase getDatabase(String schemaName)
        +MongoCollection getCollection(String schemaName, String tableName)
        +void insert(String schemaName, String tableName, List~Document~ documents)
        +MongoCursor query(String schemaName, String tableName, Bson filter, Bson projection)
    }

    class WriteConcernType {
        <<enumeration>>
        +ACKNOWLEDGED
        +JOURNALED
        +MAJORITY
        +UNACKNOWLEDGED
        -WriteConcern writeConcern
        +WriteConcernType(WriteConcern writeConcern)
        +WriteConcern getWriteConcern()
    }

    class SslContextProvider {
        +SslContextProvider(String truststorePath, String truststorePassword, String keystorePath, String keystorePassword)
        +Optional~SSLContext~ buildSslContext()
    }

    class MongoClientSettings_Builder {
        +MongoClientSettings_Builder applyConnectionString(ConnectionString connectionString)
        +MongoClientSettings_Builder applyToConnectionPoolSettings(ConnectionPoolSettingsCallback callback)
        +MongoClientSettings_Builder applyToSocketSettings(SocketSettingsCallback callback)
        +MongoClientSettings_Builder applyToClusterSettings(ClusterSettingsCallback callback)
        +MongoClientSettings_Builder applyToSslSettings(SslSettingsCallback callback)
        +MongoClientSettings_Builder writeConcern(WriteConcern writeConcern)
        +MongoClientSettings_Builder readPreference(ReadPreference readPreference)
        +MongoClientSettings build()
    }

    class MongoClients {
        +static MongoClient create(MongoClientSettings settings)
    }

    class MongoClient {
        +MongoDatabase getDatabase(String name)
        +void close()
    }

    MongoClientModule ..> MongoClientConfig : uses
    MongoClientModule ..> MongoSession : creates
    MongoClientModule ..> MongoClientSettings_Builder : configures
    MongoClientModule ..> MongoClients : createsMongoClient
    MongoClientModule ..> SslContextProvider : tlsConfiguration
    MongoClientModule ..> WriteConcernType : uses
    MongoSession ..> MongoClient : holds
    MongoClientConfig ..> WriteConcernType : returns
    WriteConcernType ..> WriteConcern : wraps
    MongoClients ..> MongoClient : returns
Loading

File-Level Changes

Change Details Files
Switch MongoDB client construction from legacy MongoClientOptions API to MongoClientSettings with connection-string based configuration.
  • Replace MongoClientOptions.Builder usage with MongoClientSettings.Builder in MongoClientModule and related tests.
  • Introduce a buildConnectionString helper to construct mongodb:// URLs from MongoClientConfig seeds and credentials, including auth DB and directConnection=false.
  • Configure connection pool, socket timeouts, write concern, read preference, replica set, and TLS via MongoClientSettings apply* settings lambdas instead of legacy setters.
  • Instantiate clients using MongoClients.create(settingsBuilder.build()) or MongoClients.create(connectionString) instead of new MongoClient(...) constructors.
presto-mongodb/src/main/java/com/facebook/presto/mongodb/MongoClientModule.java
presto-mongodb/src/test/java/com/facebook/presto/mongodb/TestMongoTlsConfiguration.java
presto-mongodb/src/test/java/com/facebook/presto/mongodb/MongoQueryRunner.java
presto-mongodb/src/test/java/com/facebook/presto/mongodb/TestMongoViews.java
Modernize TLS/SSL configuration in tests and production code to use MongoClientSettings SSL settings.
  • Refactor TLS-related tests to assert against MongoClientSettings.getSslSettings() instead of MongoClientOptions SSL flags and context.
  • Wire SslContextProvider into MongoClientSettings via applyToSslSettings(enabled/context) instead of options.sslEnabled/sslContext.
  • Ensure full client-creation flow test verifies connection pool and socket settings via MongoClientSettings rather than legacy options.
presto-mongodb/src/test/java/com/facebook/presto/mongodb/TestMongoTlsConfiguration.java
presto-mongodb/src/main/java/com/facebook/presto/mongodb/MongoClientModule.java
Align write concern enum with write concerns supported by the newer MongoDB driver.
  • Remove deprecated/legacy write concern constants from WriteConcernType, keeping only ACKNOWLEDGED, JOURNALED, MAJORITY, and UNACKNOWLEDGED.
  • Continue to expose WriteConcernType.getWriteConcern() for use in MongoClientSettings.writeConcern().
presto-mongodb/src/main/java/com/facebook/presto/mongodb/WriteConcernType.java
Update MongoDB driver dependencies to the mongodb-driver-sync 5.6.5 stack and add explicit submodules.
  • Bump mongo-java.version from 3.12.14 to 5.6.5 in the presto-mongodb module.
  • Switch the main MongoDB dependency from mongo-java-driver to mongodb-driver-sync.
  • Add explicit dependencies on mongodb-driver-core and bson at the same version.
presto-mongodb/pom.xml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@josephglerin josephglerin marked this pull request as ready for review April 29, 2026 12:14
@josephglerin josephglerin requested a review from a team as a code owner April 29, 2026 12:14
@prestodb-ci prestodb-ci requested review from a team, Shreya-ibm and anees-kt and removed request for a team April 29, 2026 12:14
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • In buildConnectionString, the connection string is manually assembled using only the first credential and without URL-encoding username/password or auth DB, which can break for special characters and may silently ignore multiple configured credentials—consider using ConnectionString-compatible formatting helpers or encoding, and either enforcing a single-credential invariant or handling multiple credentials explicitly.
  • The new MongoClientSettings configuration drops socketKeepAlive(config.getSocketKeepAlive()) from the old MongoClientOptions setup, so if that flag is still meaningful in MongoClientConfig you may want to map it to the driver’s equivalent (or explicitly deprecate/ignore it in the config).
  • Since mongodb-driver-sync already pulls in mongodb-driver-core and bson, you may be able to avoid explicitly declaring those extra dependencies in the POM unless there is a strong reason to keep them direct.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `buildConnectionString`, the connection string is manually assembled using only the first credential and without URL-encoding username/password or auth DB, which can break for special characters and may silently ignore multiple configured credentials—consider using `ConnectionString`-compatible formatting helpers or encoding, and either enforcing a single-credential invariant or handling multiple credentials explicitly.
- The new `MongoClientSettings` configuration drops `socketKeepAlive(config.getSocketKeepAlive())` from the old `MongoClientOptions` setup, so if that flag is still meaningful in `MongoClientConfig` you may want to map it to the driver’s equivalent (or explicitly deprecate/ignore it in the config).
- Since `mongodb-driver-sync` already pulls in `mongodb-driver-core` and `bson`, you may be able to avoid explicitly declaring those extra dependencies in the POM unless there is a strong reason to keep them direct.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

@nishithakbhaskaran nishithakbhaskaran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josephglerin Thanks for the PR.

Please update the release note and PR title based on the guidelines.

@josephglerin josephglerin changed the title upgrading mongodb driver to mongodb driver synch chore(deps): Upgrading mongodb driver to mongodb driver synch Apr 29, 2026
@josephglerin
Copy link
Copy Markdown
Author

Testing

image

Copy link
Copy Markdown
Member

@agrawalreetika agrawalreetika left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.
Is it going to be backward compatible? Please check the existing MongoDB doc and update the version requirement if any, accordingly - https://prestodb.io/docs/current/connector/mongodb.html

.connectionsPerHost(config.getConnectionsPerHost())
.connectTimeout(config.getConnectionTimeout())
.socketTimeout(config.getSocketTimeout())
.socketKeepAlive(config.getSocketKeepAlive())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

socketKeepAlive is removed?


// Add credentials if present
if (!config.getCredentials().isEmpty()) {
MongoCredential credential = config.getCredentials().get(0);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there are multiple credentials provided? I see the config is MongoCredential list

Comment on lines +98 to +104
if (!config.getCredentials().isEmpty()) {
MongoCredential credential = config.getCredentials().get(0);
connectionString.append(credential.getUserName())
.append(":")
.append(new String(credential.getPassword()))
.append("@");
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we set credentials via settingsBuilder directly instead of exposing it as a String in connectionString?

String connectionString = buildConnectionString(config);
settingsBuilder.applyConnectionString(new ConnectionString(connectionString));

// Connection pool settings
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: i think we can remove these one-liner comments in different places

}

// directConnection=false forces replica set discovery to find the primary
connectionString.append("?directConnection=false");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose for single node deployment, we don't need discovery? Should we only use directConnection=false for replica sets?

@agrawalreetika agrawalreetika changed the title chore(deps): Upgrading mongodb driver to mongodb driver synch chore(deps): Upgrading mongodb driver to mongodb driver sync Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:IBM PR from IBM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants