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');

Example;

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('45.79.40.64:27017', 'local', 'startup_log', 'root', 'root');

Run the query in ClickHouse;

SELECT COUNT() FROM mongo_table;

Result;

┌─count()─┐
│      47 │
└─────────┘

To read from an SSL-secured MongoDB server;

CREATE TABLE mongo_table_ssl
 (
     key UInt64,
     data String
 ) ENGINE = MongoDB('45.79.40.64:27017', '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('45.79.40.64:27017', 'local', 'startup_log', 'root', 'root', 'connectTimeoutMS=100000');

 

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

Was this article helpful?

Related Articles

CHISTADATA IS COMMITTED TO OPEN SOURCE SOFTWARE AND BUILDING HIGH PERFORMANCE COLUMNSTORES

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

http://www.apache.org/licenses/LICENSE-2.0

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.