Skip to content

Instantly share code, notes, and snippets.

@deepal
Last active February 15, 2022 21:01
Show Gist options
  • Save deepal/e95dbd00ab4d1942df99234aa2ea207d to your computer and use it in GitHub Desktop.
Save deepal/e95dbd00ab4d1942df99234aa2ea207d to your computer and use it in GitHub Desktop.
const client = new MongoClient(MONGODB_CONNECTION_STRING);
await client.connect();
const collection = client.db("myapp").collection("outbox");
/*
watch() function accepts an aggregation pipeline, which can be used to perform
additional aggregation stages. Check out MongoDB aggregation framework for more info:
https://docs.mongodb.com/manual/core/aggregation-pipeline/
*/
const changeStream = collection.watch([
{
$match: { operationType: "insert" },
},
]);
changeStream.on("change", (changeEvent) => {
/*
dispatchToBroker function will perform any transformation
to the change event before sending it to the message broker
*/
dispatchToBroker(changeEvent)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment