I have a data table that represents results from several devices. Columns are Name, Size, Steps, Time.
I would like to create a workflow that will, on every new state received, calculate a minimum on the “Time” column and push the “Name” from that line into a new virtual device, for display on the dashboard.
I do not know MongoDB, can anyone help, please?
I am looking for just a bit more information to help you here: are you trying to implement a MongoDB Node to update an already existing MongoDB database? Or are you trying to update a Losant Data Table with MongoDB Data?
In addition, what do you mean by “new virtual device”?
If you are trying to update values to new ones within the Mongo database, I would recommend taking a look at our MongoDB Node documentation. The way I would accomplish this is by placing z MongoDB Node after function node, which can be used to modify your payload data before updating it. Here is an example below:
Thank you for your reply.
I have used a create Losant data table node to store results from several devices. The table headers are “name”, “time” “distance”.
What I want is to create a node that will search the table for the minimal value on the time column, then extract the “name” property associated with that line. I want to use that valu in another node (“device command”) to set a variable in a second device to the “name” value extracted from the table. I will use an indicator node on a dashboard to display that “name” that corresponds to the minimum “time”
To find the minimal time value, which will be the oldest time value, you will need to implement a Function Node. Below you can see more on how to do this:
Here I have a workflow with a Table: Get Rows node that calls all of the data from my Data Table and stores it in an array on the payload. Adding a function node, we format the time correctly so it can be read as a number, and then the smallest value will be at the top of my array with correctly formatted numbers. You can also see all other available data for the row in the data table. For example, you can see “id”, “title”, and many other data points within the array. You can then use this data to set a variable in another device, like you mentioned, with the name on the payload. Here is an example of using a payload value to update another device:
Hopefully this helps,