Handle non-insert changes
This commit is contained in:
parent
4b8591f51e
commit
26e79bbb20
@ -33,7 +33,6 @@ async function run() {
|
||||
console.log("Started watching changes in database");
|
||||
|
||||
const writeMessage = (response, blob) => {
|
||||
// TODO: why no id?
|
||||
const id = blob._id || null
|
||||
const message = `id: ${id}\nevent: message\ndata: ${JSON.stringify(blob)}\n\n`
|
||||
response.write(message)
|
||||
@ -55,8 +54,11 @@ async function run() {
|
||||
});
|
||||
|
||||
const changeListener = async (change) => {
|
||||
// Ignore events without fullDocument, e.g. deletes.
|
||||
if (change.fullDocument) {
|
||||
writeMessage(response, change.fullDocument)
|
||||
}
|
||||
}
|
||||
changeStream.on("change", changeListener);
|
||||
response.on('close', () => {
|
||||
changeStream.removeListener("change", changeListener)
|
||||
|
Loading…
Reference in New Issue
Block a user