简体   繁体   中英

how to get my front-end updated when I add to my database?

I'm designing a real-estate website and I was wondering can I link my front-end webpage that shows the available properties for sale that a new property icon is added when I add to my MongoDB? to elaborate more, I have a template for each single property which includes picture and some other info about the property, what i want to do is when i add a new collection to my database to appear on my webpage with this template. Thanks in advance

MongoDB can be watched , since your question has 'node.js' tag so assume you use node.js in the server side, I check the doc and there's a watch API returning a ChangeStream object which you may use, just for your reference

If you want to use angular for retrieving and showing data.

You can refer to these sites: This one tells how to populate data in angular. & To get a crisp of doing it with mongo db

What you actually need is server side event system updating your frontend, Changestream that @user1108069 mentioned can be useful in detecting new changes or you can literally identify that when a request is being made to add a new property.

The task here is to update the frontend's current connections to update their view to get the new (load) changes, you can do this in multiple ways.

  1. Use something like firebase realtime DB on the side Firebase Realtime DB
  2. Use any other server side events broker for you This should work too
  3. You can create your own full duplex system, using something like socket.io but do remember that concurrent connections needs to be handled properly. You cannot keep them connected to your server all the time.

Cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM