I have a customized ui template to display some real time information. The info is currently stored and updated in a mongo database. Is there a way to access the mongoDB in the template node? More specifically, how could I have the mongo node.js driver running inside the template?
I am also thinking of linking a mongoDB watch node to the template, but I have not succeeded in making the watch node functional. If anyone has idea about how it should be configured, please share with me!
The “code” inside the ui_template node is javascript that runs inside the browser… so I don’t think it makes sense to connect directly to your database from there. Typically, the backend node-red flow gathers the data and passes it to the ui node(s) for display – any “logic” you may want to put inside the template node would be for controlling the UI experience.
I guess I am expecting the dashboard to do more than what it is supposed to do.
I want it not only to display the information but also to act on the user’s action and choose what to display (e.g. only a subset of the data) dynamically – for that I will either need a mechanism to access mongoDB in the dashboard, or keep a copy of the entire data set locally elsewhere (a .csv for example) and use XTMLHttpRequest, which kinda defeats the purpose of having the DB.
It is not about what it is supposed to do but about what it is even possible. As Steve said the dashboard code runs in the browser which may be on a different computer to node red and cannot have a direct connection to the database. A technique you can use is to send a message from the button back to node red and in node red query the database as appropriate to get the filtered data and feed the result back to the template via another message.
That is indeed a possible solution. Instead of using a button, I manage to have the indirect access to mongo by XMLHttpRequest inside the template, combined with http nodes in the backend.