{"version":"1.0","type":"rich","title":"Emit event with Mongoose","description":"The example shows how to emit a custom event after a Mongoose document is saved, using a post-save hook. The code defines `UserSchema.post('save', function() {...})`, which triggers a `'changed'` event on the document instance, passing the document and its `altered` field as arguments. After emitting, the hook deletes `this.altered` to clean up. This demonstrates Mongoose's middleware system and Node.js's `EventEmitter` pattern for observing model changes, without any visualization library or rendering data involved.","provider_name":"VizHub AI Studio","provider_url":"https://next.vizhub.com","html":"<iframe src=\"https://next.vizhub.com/viz/gist-1334904?mode=embed\" width=\"960\" height=\"500\" scrolling=\"no\" frameborder=\"1\"></iframe>","width":960,"height":500,"cache_age":3600}