Skip to content

Instantly share code, notes, and snippets.

@daveroma
Created May 1, 2016 15:04
Show Gist options
  • Save daveroma/e0e94c8d1b997008264f8fe2d4b10b30 to your computer and use it in GitHub Desktop.
Save daveroma/e0e94c8d1b997008264f8fe2d4b10b30 to your computer and use it in GitHub Desktop.
Do something when a document is added to a MongoDB collection in Meteor
Meteor.startup(function() {
let leadsLoaded = false;
let leadsCursor = Leads.find();
Meteor.subscribe('leads', function() {
leadsLoaded = true;
});
leadsCursor.observe({
added: function(doc) {
if(leadsLoaded) {
const title = 'You Have a New Lead!';
const body = `Name: ${doc.first_name} ${doc.last_name}`;
renderDesktopNotification(title, body);
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment