Complete the code to create a trigger that runs on document insert.
exports = function(changeEvent) { if (changeEvent.operationType === '[1]') { console.log("Document inserted"); } };The trigger listens for the insert operation type to run when a new document is added.
Complete the code to access the full document after an update in a trigger.
exports = function(changeEvent) { const fullDoc = changeEvent.[1]; console.log(fullDoc); };The fullDocument field contains the entire document after the update.
Fix the error in the trigger code to correctly check for a delete operation.
exports = function(changeEvent) { if (changeEvent.operationType === '[1]') { console.log("Document deleted"); } };The correct operationType for a delete event is delete.
Fill both blanks to filter trigger events only for updates on the 'status' field.
exports = function(changeEvent) { if (changeEvent.operationType === '[1]' && changeEvent.updateDescription.updatedFields.[2] !== undefined) { console.log("Status field updated"); } };The trigger checks for update operations and specifically if the status field was changed.
Fill all three blanks to log the document ID and new value of 'score' after an update.
exports = function(changeEvent) { const docId = changeEvent.[1]._id; const newScore = changeEvent.updateDescription.updatedFields.[2]; console.log(`Document ID: ${docId}, New Score: ${newScore}`); if (changeEvent.operationType === '[3]') { /* additional logic */ } };The documentKey holds the document ID, score is the updated field, and the operationType is update.