Triggering an Email From Database Updates with MongoDB Stitch

Managing people budgets, salaries, hiring plans, raises, and equity grants for a large growing engineering team can be challenging. State of the art technology for doing so: spreadsheets. So for MongoDB, I decided to build a Stitch app to pull all the data together. That way I can manage the hiring plan, do projections, etc… It’s been quite useful, and it’s fun dogfooding Stitch.

The last feature request I got was to send an email when a new position opened up. Since Stitch Triggers just launched, this was really easy.

I started by creating a trigger in my Stitch app. (If you don’t have a Stitch app, you can create one in 10 seconds, and you don’t have to worry about going down a rathole, you can use Triggers independently of any other feature.)

Then I added an AWS Service (which just required putting in IAM credentials).

I set it up to trigger only for inserts on this collection. The code for the trigger is just this, and we’re done.

exports =  function(changeEvent) {
var hire = changeEvent.fullDocument;
var ses ="ses1-eliothorowitz");

var body = "A new hire has been added\n";
body += "Notes: " + hire.notes + "\n";
body += "Job Code: " + hire.job_code + "\n";
body += "Manager: " + hire.managerName + "\n";
body += "Salary: $" + hire.salary.toLocaleString() + "\n";
body += "Start Quarter: " + hire.startQuarter + "\n";

var to = [];

MongoDB Core Contributor; CTO MongoDB

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store