Can we update/Upsert a record in mongodb? data source is kafka

删除回忆录丶 提交于 2020-04-06 03:08:37

问题


We can update/upsert the record in mongodb BUT is there is any method or function from which we can update or upsert the document directly in mongodb and the source system is kafka and destination is mongodb.


回答1:


Yes we can update/upsert the data. For update you have to define a parameter in Kafka connector. and whitelist the column on which bases you want to update the record. The property is as followed:

document.id.strategy=com.mongodb.kafka.connect.sink.processor.id.strategy.PartialValueStrategy
value.projection.list=tokenNumber
value.projection.type=whitelist
writemodel.strategy=com.mongodb.kafka.connect.sink.writemodel.strategy.UpdateOneTimestampsStrategy



回答2:


I was struggling through it finally I got the answer. I used following Mongodb sink connector

And after bugging my head on their document for sometime ,I finally figured out the solution .

This is the exact mongodb sink connector configuration I am using

{
  "name": "mongodbsync",
  "connector.class": "at.grahsl.kafka.connect.mongodb.MongoDbSinkConnector",
  "topics": "alpha-foobar",
  "mongodb.connection.uri": "mongodb://localhost:27017/kafkaconnect?w=1&journal=true",
  "mongodb.document.id.strategy": "at.grahsl.kafka.connect.mongodb.processor.id.strategy.ProvidedInValueStrategy"

}

I left mongodb.writemodel.strategy blank in my configuration so it is taking the default one

I used the use case 2 of following docs from github of the same connector

I was dealing with this scenario ,transferring mysql table data with kafka-jdbc-source connect to mongodb sink.

Also the above strategies can be found in the official docs as well Please free to ask any doubts if you have .Thanks



来源:https://stackoverflow.com/questions/59245208/can-we-update-upsert-a-record-in-mongodb-data-source-is-kafka

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!