1. Home
  2. Knowledge Base
  3. ClickHouse DBA
  4. Ingesting Data From MongoDB

Ingesting Data From MongoDB

In this article, you will learn how to read your data from ClickHouse which is stored in MongoDB.

MongoDB engine is read-only table engine which allows to read data (SELECT queries) from remote MongoDB collection. Engine supports only non-nested data types. INSERT queries are not supported.

First, you have to create a table in ClickHouse which is related with the MongoDB parameters. Table engine in ClickHouse should be MongoDB and for the table parameter you should give your MongoDB connection informations.

CREATE TABLE mongo_table
     key UInt64,
     data String
 ) ENGINE = MongoDB('host:port', 'dbName', 'collectionName', 'username', 'password');


I am going to read startup_log collection data located on local database in MongoDB. So, i am going to create a table in ClickHouse;

CREATE TABLE mongo_table
     key UInt64,
     data String
 ) ENGINE = MongoDB('', 'local', 'startup_log', 'root', 'root');

Run the query in ClickHouse;

SELECT COUNT() FROM mongo_table;


│      47 │

To read from an SSL-secured MongoDB server;

CREATE TABLE mongo_table_ssl
     key UInt64,
     data String
 ) ENGINE = MongoDB('', 'local', 'startup_log', 'root', 'root', 'ssl=true');

You can also adjust the connection timeout;

CREATE TABLE mongo_table_to
     key UInt64,
     data String
 ) ENGINE = MongoDB('', 'local', 'startup_log', 'root', 'root', 'connectTimeoutMS=100000');


To more information, please visit official ClickHouse docs in here.

Was this article helpful?

Related Articles


In the spirit of freedom, independence and innovation. ChistaDATA Corporation is not affiliated with ClickHouse Corporation 

Need Support?

Can't find the answer you're looking for?
Contact Support

ChistaDATA Inc. Knowledge base is licensed under the Apache License, Version 2.0 (the “License”)

Copyright 2022 ChistaDATA Inc

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at


Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.