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.

Creating a Table

  1. CREATE TABLE [IF NOT EXISTS] [db.]table_name
  2. (
  3. name1 [type1],
  4. name2 [type2],
  5. ...
  6. ) ENGINE = MongoDB(host:port, database, collection, user, password [, options]);

Engine Parameters

  • host:port — MongoDB server address.

  • database — Remote database name.

  • collection — Remote collection name.

  • user — MongoDB user.

  • password — User password.

  • options — MongoDB connection string options (optional parameter).

Usage Example

Create a table in ClickHouse which allows to read data from MongoDB collection:

  1. CREATE TABLE mongo_table
  2. (
  3. key UInt64,
  4. data String
  5. ) ENGINE = MongoDB('mongo1:27017', 'test', 'simple_table', 'testuser', 'clickhouse');

To read from an SSL secured MongoDB server:

  1. CREATE TABLE mongo_table_ssl
  2. (
  3. key UInt64,
  4. data String
  5. ) ENGINE = MongoDB('mongo2:27017', 'test', 'simple_table', 'testuser', 'clickhouse', 'ssl=true');

Query:

  1. SELECT COUNT() FROM mongo_table;
  1. ┌─count()─┐
  2. 4
  3. └─────────┘