Home > database >  Update HTML page on mongodb data change
Update HTML page on mongodb data change

Time:12-06

I want to update the HTML/pug page of multiple users when particular data changes in my MongoDB database. A user(A) follows another user(B) (whose data is stored in a different collection). When user(B) updates something, user(A) should see the change. There can be multiple people following the same user, and all the people following the user should see live updates.

I tried looking into socket.io but it doesn't look like it is the right thing for my purpose.

CodePudding user response:

Your main options are either websockets (socket.io), server side push notifications with http2, or polling with http.

If socket.io seems overkill, server push notifications probably will too.

You can poll instead. Ie, send an http request from the client at regular intervals, like every 10 (or whatever seems suitable) seconds and update the page based on the response data

You’ll need to use JavaScript on the client for this. Pug templates render just once on page load. If you want dynamic updates after the initial render, you need client side JavaScript in all cases.

  • Related