DEV Community

Discussion on: IoT-SaaS: Web App using ReactJS, MongoDB Atlas & Realm

Collapse
 
longvd89 profile image
longvd89

Hi. I am building a iot project. I have a lists of pi with data sensor sub from mqtt topic. How I can update realtime data for each only a row in table when data sensor change. Thanks

Collapse
 
tagorenathv profile image
TagorenathV

sync all data to a timeseries collection lets say sensor_data initially from mqtt topic. For every scheduled time, perform aggregation on this sensor_data and write updated data to aggregated_sensor_data. We have upsert operation in mongo. take pi device id as key reference and apply upsert operation on aggregated_sensor_data. now, at any given time you will have updated value for pi devices in aggregated_sensor_data collection.

Benefits: Because raw data is in timeseries collection, you can mention expireSeconds. aggregated_data collection could be normal collection type and can use this for database triggers. (At the moment, we cant use timeseries collection for realm-database-triggers)

Collapse
 
longvd89 profile image
longvd89

I want to ask the solution on front end with react

Thread Thread
 
tagorenathv profile image
TagorenathV

From UI perspective we just give a json response to populate a chart. For fetching that value for a pid we need to use mongo aggregation pipeline. Please check this if it helps:
github.com/tagorenathv/iot-saas/bl...