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,7 +54,10 @@ async function run() {
|
||||
});
|
||||
|
||||
const changeListener = async (change) => {
|
||||
writeMessage(response, change.fullDocument)
|
||||
// Ignore events without fullDocument, e.g. deletes.
|
||||
if (change.fullDocument) {
|
||||
writeMessage(response, change.fullDocument)
|
||||
}
|
||||
}
|
||||
changeStream.on("change", changeListener);
|
||||
response.on('close', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user