Last active
February 15, 2022 21:01
-
-
Save deepal/e95dbd00ab4d1942df99234aa2ea207d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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