title_wip

```
<clickhouse>
    <named_collections>
        <remote1>
            <host>remote_host</host>
            <port>9000</port>
            <database>system</database>
            <user>foo</user>
            <password>secret</password>
            <secure>1</secure>
        </remote1>
    </named_collections>
</clickhouse>
```

`secure` is not needed for connection because of `remoteSecure`, but it can be used for dictionaries.

### Example of using named collections with the `remote`/`remoteSecure` functions[​](#example-of-using-named-collections-with-the-remoteremotesecure-functions "Direct link to example-of-using-named-collections-with-the-remoteremotesecure-functions")

```
SELECT * FROM remote(remote1, table = one);
┌─dummy─┐
│     0 │
└───────┘

SELECT * FROM remote(remote1, database = merge(system, '^one'));
┌─dummy─┐
│     0 │
└───────┘

INSERT INTO FUNCTION remote(remote1, database = default, table = test) VALUES (1,'a');

SELECT * FROM remote(remote1, database = default, table = test);
┌─a─┬─b─┐
│ 1 │ a │
└───┴───┘
```

### Example of using named collections with a dictionary with source ClickHouse[​](#example-of-using-named-collections-with-a-dictionary-with-source-clickhouse "Direct link to Example of using named collections with a dictionary with source ClickHouse")

```
CREATE DICTIONARY dict(a Int64, b String)
PRIMARY KEY a
SOURCE(CLICKHOUSE(NAME remote1 TABLE test DB default))
LIFETIME(MIN 1 MAX 2)
LAYOUT(HASHED());

SELECT dictGet('dict', 'b', 1);
┌─dictGet('dict', 'b', 1)─┐
│ a                       │
└─────────────────────────┘
```

## Named collections for accessing Kafka[​](#named-collections-for-accessing-kafka "Direct link to Named collections for accessing Kafka")

The description of parameters see [Kafka](/docs/engines/table-engines/integrations/kafka).

### DDL example[​](#ddl-example-3 "Direct link to DDL example")

```
CREATE NAMED COLLECTION my_kafka_cluster AS
kafka_broker_list = 'localhost:9092',
kafka_topic_list = 'kafka_topic',
kafka_group_name = 'consumer_group',
kafka_format = 'JSONEachRow',
kafka_max_block_size = '1048576';
```

### XML example[​](#xml-example-3 "Direct link to XML example")

```
<clickhouse>
    <named_collections>
        <my_kafka_cluster>
            <kafka_broker_list>localhost:9092</kafka_broker_list>
            <kafka_topic_list>kafka_topic</kafka_topic_list>
            <kafka_group_name>consumer_group</kafka_group_name>
            <kafka_format>JSONEachRow</kafka_format>
            <kafka_max_block_size>1048576</kafka_max_block_size>
        </my_kafka_cluster>
    </named_collections>
</clickhouse>
```

### Example of using named collections with a Kafka table[​](#example-of-using-named-collections-with-a-kafka-table "Direct link to Example of using named collections with a Kafka table")

Both of the following examples use the same named collection `my_kafka_cluster`:

```
CREATE TABLE queue
(
    timestamp UInt64,
    level String,
    message String
)
ENGINE = Kafka(my_kafka_cluster)

CREATE TABLE queue
(
    timestamp UInt64,
    level String,
    message String
)
ENGINE = Kafka(my_kafka_cluster)
SETTINGS kafka_num_consumers = 4,
         kafka_thread_per_consumer = 1;
```

## Named collections for backups[​](#named-collections-for-backups "Direct link to Named collections for backups")

For the description of parameters see [Backup and Restore](/docs/operations/backup/overview).

### DDL example[​](#ddl-example-4 "Direct link to DDL example")

```
BACKUP TABLE default.test to S3(named_collection_s3_backups, 'directory')
```

### XML example[​](#xml-example-4 "Direct link to XML example")

```
<clickhouse>
    <named_collections>
        <named_collection_s3_backups>
            <url>https://my-s3-bucket.s3.amazonaws.com/backup-S3/</url>
            <access_key_id>ABC123</access_key_id>
            <secret_access_key>Abc+123</secret_access_key>
        </named_collection_s3_backups>
    </named_collections>
</clickhouse>
```

## Named collections for accessing MongoDB Table and Dictionary[​](#named-collections-for-accessing-mongodb-table-and-dictionary "Direct link to Named collections for accessing MongoDB Table and Dictionary")

For the description of parameters see [mongodb](/docs/sql-reference/table-functions/mongodb).

### DDL example[​](#ddl-example-5 "Direct link to DDL example")

```
CREATE NAMED COLLECTION mymongo AS
user = '',
password = '',
host = '127.0.0.1',
port = 27017,
database = 'test',
collection = 'my_collection',
options = 'connectTimeoutMS=10000'
```

### XML example[​](#xml-example-5 "Direct link to XML example")

```
<clickhouse>
    <named_collections>
        <mymongo>
            <user></user>
            <password></password>
            <host>127.0.0.1</host>
            <port>27017</port>
            <database>test</database>
            <collection>my_collection</collection>
            <options>connectTimeoutMS=10000</options>
        </mymongo>
    </named_collections>
</clickhouse>
```

#### MongoDB table[​](#mongodb-table "Direct link to MongoDB table")

```
CREATE TABLE mytable(log_type VARCHAR, host VARCHAR, command VARCHAR) ENGINE = MongoDB(mymongo, options='connectTimeoutMS=10000&compressors=zstd')
SELECT count() FROM mytable;

┌─count()─┐
│       2 │
└─────────┘
```

Note

The DDL overrides the named collection setting for options.

#### MongoDB Dictionary[​](#mongodb-dictionary "Direct link to MongoDB Dictionary")

```
CREATE DICTIONARY dict
(
    `a` Int64,
    `b` String
)
PRIMARY KEY a
SOURCE(MONGODB(NAME mymongo COLLECTION my_dict))
LIFETIME(MIN 1 MAX 2)
LAYOUT(HASHED())

SELECT dictGet('dict', 'b', 2);

┌─dictGet('dict', 'b', 2)─┐
│ two                     │
└─────────────────────────┘
```

Note

The named collection specifies `my_collection` for the collection name. In the function call it is overwritten by `collection = 'my_dict'` to select another collection.