First, you must download the proper Kafka certficiates and convert them to the format required by SSL via Node.js.
Convert the .p12 files to the required user.key, cluster.crt, and user.crt files. When propmted, use the appropriate cluster certficiate password or user password as described in the portal.
For the onDocumentChanged function, we will parse the event into one of three possible types: Insert, Update, and Remove.
Inserting a New Document
When change.oldValue is equal to null, that means that a new document was inserted into the database.
Node.js
if(transaction.change.method ==='update'&& transaction.change.oldValue ===null){letchange: DittoInsert = transaction.change
const result =await collection.insertOne(change.newValue);
console.log(`A document was inserted with the _id: ${result.insertedId}`,);}
Updating an Existing Document
If change.oldValue has a value, that means that a document with the corresponding _id was updated to the value indicated in change.newValue.
Send an HTTP request to tell the Ditto Big Peer to catch up to the given transaction id as part of transaction.txnId and the given collection.
Your HTTP endpoint will look like https://${APP_ID}.cloud.ditto.live.