Friday 24 February 2017

Notification system based on MongoDB documents?

I am currently developing a web app that uses Node.js, Express, and MongoDB. It is based off of [KeystoneJS](keystonejs.com) for data, route, and user management. I'm looking for a way to create a notification system based off of new or changed MongoDB documents in my app.To clarify, I am not talking about HTML5 popup/notification boxes. I'm talking about notifications native to my application that let users view notices specific to them, and come back to them later. A la Facebook notifications.Say, for example, someone signs up to attend a specific event. I want to send a notification to the organizer of that event, letting them know who has signed up. I already have functionality in order to view the details of who has signed up, but I just want there to be some sort of client-facing alert once it happens (other than them checking a list). The idea would be for it to look something like this:[Person Name] has RSVP'ed for [Event Name]!There are two ways that I can go about this:1. Adding a Notification model to MongoDB and creating a Notification every time someone registersI'm not opposed to this due to how simple it would be, but I'm concerned as to how much size it would take up in the database. What I would probably do is prune notifications every seven days so that only the most recent are kept, but I would rather not delete notifications if I can help it. I am fine with notifications not appearing until a new page loads, though it would be nice if it were instant somehow (frontend AJAX or something).2. Socket.io notifications in real timeI don't dislike this idea, but I don't know how notifications would be stored so that users would be able to come back to a notification if they're not right there when it occurs. Would the notifications be stored in a database? Or temporarily? What happens when the server resets? How can I have it persist between reboots, and potentially have the ability to delete notifications at will?Which option would be the best for me? Is there a better, third option that is not occuring to me?Thank you!

Submitted February 24, 2017 at 08:59PM by TheD3xus

No comments:

Post a Comment