ClickHouse/docs/en/engines/table-engines/integrations/mongodb.md

58 lines
1.2 KiB
Markdown
Raw Normal View History

2021-02-07 14:29:54 +00:00
---
toc_priority: 7
toc_title: MongoDB
---
# MongoDB {#mongodb}
2021-02-08 14:30:15 +00:00
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.
2021-02-07 14:29:54 +00:00
## Creating a Table {#creating-a-table}
``` sql
CREATE TABLE [IF NOT EXISTS] [db.]table_name
(
name1 [type1],
name2 [type2],
...
) ENGINE = MongoDB(host:port, database, collection, user, password);
```
**Engine Parameters**
- `host:port` — MongoDB server address.
- `database` — Remote database name.
2021-02-08 14:30:15 +00:00
- `collection` — Remote collection name.
2021-02-07 14:29:54 +00:00
- `user` — MongoDB user.
- `password` — User password.
## Usage Example {#usage-example}
2021-02-08 14:30:15 +00:00
Table in ClickHouse which allows to read data from MongoDB collection:
2021-02-07 14:29:54 +00:00
``` text
CREATE TABLE mongo_table
(
key UInt64,
data String
2021-02-08 14:30:15 +00:00
) ENGINE = MongoDB('mongo1:27017', 'test', 'simple_table', 'testuser', 'clickhouse');
2021-02-07 14:29:54 +00:00
```
Query:
``` sql
SELECT COUNT() FROM mongo_table;
```
``` text
┌─count()─┐
│ 4 │
└─────────┘
```
[Original article](https://clickhouse.tech/docs/en/operations/table_engines/integrations/mongodb/) <!--hide-->