Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 408
nixxo_raa Avatar asked Dec 09 '19 08:12

nixxo_raa


People also ask

What is Kafka source connector?

The Kafka Connect JMS Source connector is used to move messages from any JMS-compliant broker into Apache Kafka®. Elasticsearch Service Sink. The Kafka Connect Elasticsearch Service Sink connector moves data from Apache Kafka® to Elasticsearch. It writes data from a topic in Kafka to an index in Elasticsearch.

What is Kafka sink connector?

The Kafka Connect JDBC Sink connector allows you to export data from Apache Kafka® topics to any relational database with a JDBC driver. This connector can support a wide variety of databases. The connector polls data from Kafka to write to the database based on the topics subscription.

Where does Kafka connect run?

Connect Worker But where do the tasks actually run? Kafka Connect runs under the Java virtual machine (JVM) as a process known as a worker. Each worker can execute multiple connectors.

How can we update a record in MongoDB?

How can we update a record in MongoDB? To update a record, you need to update on the basis of _id. Let us create a collection with documents − Display all documents from a collection with the help of find () method −

What is upsert in MongoDB?

Summary: in this tutorial, you’ll learn how to use the MongoDB upsert function. Upsert is a combination of up date and in sert. Upsert performs two functions:

What is the use of updateone method in MongoDB?

The updateOne method updates a single document in a collection based on the applied query filter. It first finds the document that matches the filter and then updates the specified fields. In addition, we can use different operators such as $set, $unset, $inc, etc., with the update method.

How to prevent MongoDB from inserting the same document more than once?

Note: To prevent MongoDB from inserting the same document more than once, create a unique index on the name field. With a unique index, if multiple documents want the same update with upsert: true, only one update operation successfully inserts a new document. db.Collection_name.update ( {Selection_criteria}, {$set: {Update_data}}, {


1 Answers

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
like image 133
nixxo_raa Avatar answered Oct 10 '22 08:10

nixxo_raa