v.23.3Improvement

External Tables in MongoDB: Replica Set URI Support and Read Preference Option

External tables from MongoDB: support for connection to a replica set via a URI with a host:port enum and support for the readPreference option in MongoDB dictionaries. Example URI: mongodb://db0.example.com:27017,db1.example.com:27017,db2.example.com:27017/?replicaSet=myRepl&readPreference=primary. #46524 (artem-yadr).
Added support for connecting ClickHouse external tables to MongoDB replica sets via a URI containing multiple hosts and ports, along with the ability to specify the readPreference option in MongoDB dictionaries.

Why it matters

This feature allows users to configure ClickHouse to connect to MongoDB replica sets more flexibly and reliably by specifying multiple hosts and the desired read preference. It improves resilience and read operation control when querying MongoDB data through ClickHouse external tables and dictionaries.

How to use it

Specify a MongoDB URI with multiple host:port entries separated by commas and include the replicaSet and readPreference options in the connection string. For example:

mongodb://db0.example.com:27017,db1.example.com:27017,db2.example.com:27017/?replicaSet=myRepl&readPreference=primary

Use this URI when configuring MongoDB dictionaries or external tables in ClickHouse to connect to the replica set and control the read preference.