Properties from external DB sample
This sample demonstrates how to connect with an external DB on demand, adding custom properties to Viewer property panel. It uses SignalR to notify different users when the parameters they might be seeing changes.
* It's important to emphasize that, in this case, we're not dealing with data from an Exchange. The goal here is to connect with data available in any external DB.
When we load a model in Viewer, it comes with its original information that got translated by Model Derivative.
Usually, it's interesting to add more data from other sources aggregated with our model, and we have multiple samples for that, for instance, by using a dashboard added to our page.
Ok, that works, but what if you don't actually need all the data from additional DB aggregated in your model?
What if you need to query specific additional data based on specific elements in your scene?
To address these scenarios we have this sample, that query data from an external DB (in this case MongoDB) based on specific element selection. This data is, then, aggregated to the element properties in properties panel.
We also have the possibility to change those properties straight from properties panel.
We can understand how it works dividing the connection to DB in two steps:
Reading Data from DB and aggregating into Property Panel
1 - User select an element from the scene, which triggers a job to retrieve associated properties (specific to this element) from an external DB (MongoDB in this case)
2 - A task retrieves the associated properties from the external DB.
3 - If those properties exists they are returned and aggregated to the properties panel inside an input element, so the user can change them. If not, the properties are aggregated on properties panel as blank inputs, so user can write values to those, creating new values in the external DB.
Updating the Properties from Viewer Property Panel
1 - User update a custom parameter on viewer’s property panel inputs, which triggers a job to update this parameters value in the external DB (MongoDB in this case).
2 - A task updates the property value (or create it, if it doesn’t exists).
3 - The client that triggered the task (A) get notified about the result, while other clients (B and C) receives a notification with the changed/created value.
And that's it.
Below you can find references for demo and source.
You can follow me on Twitter: twitter.com/JooPaulodeOrne2