0

Sorry if my question is abstract but let me explain my problem. I've got a forum that looks like to StackOverflow and built on nodejs and mongodb. There is posts and comments. I need to implement notification system which allows to notify users about adding a new answer to a post, changing post content, adding a new comments.

My problem is I've never implemented this feature before so at now I'm looking for best practices before I start. What I'm primary interested in is generic pattern of implementing this system. In particular what schema for notifications collection is needed? How to determinate subscribers to a post to send an notification? and other nuances which might be in such system.

Just to clarify that I don't need real-time notifications such in facebook but list of notifications at the top (like in SO) and ability to notify by email.

Please give some whitepapers on such system in an internet or some advises on how to implement such system from scratch.

Thanks.

Erik
  • 14,060
  • 49
  • 132
  • 218

3 Answers3

0

Look up websockets (i.e socket.io or faye)

mjarraya
  • 1,116
  • 1
  • 11
  • 18
  • Just to clarify that I don't need real-time notifications such in facebook but list of notifications at the top (like in SO) and ability to notify by email – Erik Nov 14 '17 at 15:04
0

listen on mongodb triggers and if your criteria has met then run a logic to get the email of user and use nodemailer to send email

varaprasadh
  • 488
  • 5
  • 13
  • You need to provide any limitations, assumptions or simplifications in your answer. See more details on how to answer at this link: https://stackoverflow.com/help/how-to-answer – Usama Abdulrehman Jun 16 '20 at 00:43
0

Starting form v3.6, MongoDB supports change streams that lets you subscribe for data changes.

For example you when you get an insert event on comments collection, you can trigger actions such as insert a new document in notifications collection, send email, etc.

You can refer to change events to see the list of events that MongoDB supports, along with the minimum version.

Alternatively, if you use Mongoose

You can also use Mongoose middlewares that provide "hooks" that lets you specify actions before or after certain operations.

For example you can specify a function that handles notifications to run after each document save operation.

thammada.ts
  • 5,065
  • 2
  • 22
  • 33