Reputation: 2010
I was wondering what the best way would be to create a user alert system with a node.js and mongoDB implementation.
Would you still have to get the client side to poll the server side and check if there are any new updates to display to the user? (For example, new messages)
Or is there an efficient way for db changes to filter down to the UI, as they happen? I am just starting out with learning node and I cannot find an answer online.
Any explanation of this would be great.
Thank you.
Upvotes: 1
Views: 1569
Reputation: 35018
For an alert system, I would use the following three components:
The capped collection would hold all the notifications (i.e. new notification are just added to the capped collection, the capped collection has the added advantage that old messages are automatically deleted), the tailable cursor would be kept open and continuously return any new messages and socket.io would be able to handle notifying the client without any effort.
Upvotes: 5
Reputation: 64318
It sounds to me the solution you're looking for is here: https://gist.github.com/scttnlsn/3210919
Upvotes: 1