# Kafka mongo sink. Create \_id from key message

**URL:** https://forum.confluent.io/t/kafka-mongo-sink-create-id-from-key-message/8653
**Category:** Kafka Connect
**Created:** [8 September 2023 19:31 UTC](https://forum.confluent.io/t/kafka-mongo-sink-create-id-from-key-message/8653 "2023-09-08T19:31:49Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ralphs](https://avatars.discourse-cdn.com/v4/letter/r/e0b2c6/32.png) [@ralphs](https://forum.confluent.io/u/ralphs)
#### Post date: [8 September 2023 19:31 UTC](https://forum.confluent.io/t/kafka-mongo-sink-create-id-from-key-message/8653/1 "2023-09-08T19:31:49Z")

</div>

Hello,

I have the following kafka message: key content is `{orderid: 123}` and the message value as `{name: "def", company: "abc"}`. I want to insert in mongodb the following document: `{_id: 123, name: "def", company: "abc"}` where \_id takes the value of orderid from the key message. I have tried the following config and it looks ok except that the \_id is being an object like this: `_id:{orderid: 123}`. Any idead how we can achieve this? I have the following config:

```auto
name = MongoSinkConnectorConnector_1
connector.class = com.mongodb.kafka.connect.MongoSinkConnector
topics = topicA

key.converter = org.apache.kafka.connect.storage.StringConverter
key.converter.schemas.enable = false

value.converter = org.apache.kafka.connect.json.JsonConverter
value.converter.schemas.enable = false

connection.uri = mongodb://localhost:27017
database = foo
collection = mycollection

# Use a single message as a document
document.id.strategy=com.mongodb.kafka.connect.sink.processor.id.strategy.PartialKeyStrategy

# Post processing of the sink documents
post.processor.chain=com.mongodb.kafka.connect.sink.processor.DocumentIdAdder

# Document ID strategy using the Partial Key Strategy
document.id.strategy.overwrite.existing=true

# Provide a custom setting for which key values to consider for the _id
document.id.strategy.partial.key.projection.list=orderid,customerid
document.id.strategy.partial.key.projection.type=AllowList

```

Thank you!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex019/uploads/confluentcommunity/original/1X/c49438c90c9df282e9996fdf6971be890c71b65a.svg) [@system](https://forum.confluent.io/u/system)
#### Post date: [8 October 2023 19:32 UTC](https://forum.confluent.io/t/kafka-mongo-sink-create-id-from-key-message/8653/2 "2023-10-08T19:32:46Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
