Ingesting data from MongoDB to ClickHouse (using CDC)

[Edit this page](https://github.com/ClickHouse/clickhouse-docs/blob/main/docs/integrations/data-ingestion/clickpipes/mongodb/index.md)

Beta feature. [Learn more.](/docs/beta-and-experimental-features#beta-features)

References

Ingesting data from MongoDB to ClickHouse Cloud via ClickPipes is in public beta.

Note

In the ClickHouse Cloud console and documentation, "table" and "collection" are used interchangeably for MongoDB.

You can use ClickPipes to ingest data from your MongoDB database into ClickHouse Cloud. The source MongoDB database can be hosted on-premises or in the cloud using services like MongoDB Atlas.

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

To get started, you first need to ensure that your MongoDB database is correctly configured for replication. The configuration steps depend on how you're deploying MongoDB, so please follow the relevant guide below:

1. [MongoDB Atlas](/docs/integrations/clickpipes/mongodb/source/atlas)
2. [Generic MongoDB](/docs/integrations/clickpipes/mongodb/source/generic)
3. [Amazon DocumentDB](/docs/integrations/clickpipes/mongodb/source/documentdb)

Once your source MongoDB database is set up, you can continue creating your ClickPipe.

## Create your ClickPipe[​](#create-your-clickpipe "Direct link to Create your ClickPipe")

Make sure you're logged in to your ClickHouse Cloud account. If you don't have an account yet, you can sign up [here](https://cloud.clickhouse.com/).

1. In the ClickHouse Cloud console, navigate to your ClickHouse Cloud Service.

2. Select the `Data Sources` button on the left-side menu and click on "Set up a ClickPipe".

3. Select the `MongoDB CDC` tile.

### Add your source MongoDB database connection[​](#add-your-source-mongodb-database-connection "Direct link to Add your source MongoDB database connection")

4. Fill in the connection details for your source MongoDB database which you configured in the prerequisites step.

   References

   Before you start adding your connection details make sure that you have whitelisted ClickPipes IP addresses in your firewall rules. On the following page you can find a [list of ClickPipes IP addresses](/docs/integrations/clickpipes#list-of-static-ips).
   For more information refer to the source MongoDB setup guides linked at [the top of this page](#prerequisites).

#### (Optional) Set up SSH Tunneling[​](#optional-set-up-ssh-tunneling "Direct link to (Optional) Set up SSH Tunneling")

You can specify SSH tunneling details if your source MongoDB database isn't publicly accessible.

1. Enable the "Use SSH Tunnelling" toggle.
2. Fill in the SSH connection details.
3. To use Key-based authentication, click on "Revoke and generate key pair" to generate a new key pair and copy the generated public key to your SSH server under `~/.ssh/authorized_keys`.
4. Click on "Verify Connection" to verify the connection.

Note

Make sure to whitelist [ClickPipes IP addresses](/docs/integrations/clickpipes#list-of-static-ips) in your firewall rules for the SSH bastion host so that ClickPipes can establish the SSH tunnel.

Once the connection details are filled in, click `Next`.

#### Configure advanced settings[​](#advanced-settings "Direct link to Configure advanced settings")

You can configure the advanced settings if needed. A brief description of each setting is provided below:

- **Sync interval**: This is the interval at which ClickPipes will poll the source database for changes. This has an implication on the destination ClickHouse service, for cost-sensitive users we recommend to keep this at a higher value (over `3600`).
- **Pull batch size**: The number of rows to fetch in a single batch. This is a best effort setting and may not be respected in all cases.
- **Snapshot number of tables in parallel**: This is the number of tables that will be fetched in parallel during the initial snapshot. This is useful when you have a large number of tables and you want to control the number of tables fetched in parallel.

### Configure the tables[​](#configure-the-tables "Direct link to Configure the tables")

5. Here you can select the destination database for your ClickPipe. You can either select an existing database or create a new one.
6. You can select the tables you want to replicate from the source MongoDB database. While selecting the tables, you can also choose to rename the tables in the destination ClickHouse database.

### Review permissions and start the ClickPipe[​](#review-permissions-and-start-the-clickpipe "Direct link to Review permissions and start the ClickPipe")

7. Select the "Full access" role from the permissions dropdown and click "Complete Setup".

## What's next?[​](#whats-next "Direct link to What's next?")

Once you've set up your ClickPipe to replicate data from MongoDB to ClickHouse Cloud, you can focus on how to query and model your data for optimal performance.

## Caveats[​](#caveats "Direct link to Caveats")

Here are a few caveats to note when using this connector:

- We require MongoDB version 5.1.0+.
- We use MongoDB's native Change Streams API for CDC, which relies on the MongoDB oplog to capture real-time changes.
- Documents from MongoDB are replicated into ClickHouse as JSON type by default. This allows for flexible schema management and makes it possible to use the rich set of JSON operators in ClickHouse for querying and analytics. You can learn more about querying JSON data [here](https://clickhouse.com/docs/sql-reference/data-types/newjson).
- Self-serve PrivateLink configuration isn't currently available. If you're on AWS and require PrivateLink, please reach out to [[email protected]](/cdn-cgi/l/email-protection#2b4f490642455f4e4c594a5f4244455806585e5b5b44595f6b484742484043445e584e05484446) or create a support ticket — we will work with you to enable it.

- [Prerequisites](#prerequisites)- [Create your ClickPipe](#create-your-clickpipe)
    - [Add your source MongoDB database connection](#add-your-source-mongodb-database-connection)- [Configure the tables](#configure-the-tables)- [Review permissions and start the ClickPipe](#review-permissions-and-start-the-clickpipe)- [What's next?](#whats-next)- [Caveats](#caveats)

Was this page helpful?