Count the messages uuid values

I have a Message which has following data
uuid (as String)
Time
Value

I need to count uuid occurances and mantain its count. How I can solve using Count the messages ?

Sample messages:
Message1: {"uuid": "abc", "time":"1645878529", "value": 50}
message2: {"uuid": "efg", "time":"1645878530", "value": 51}
and so on

Expected output:
{"abc": 5, "efg": 10}

You can do it with a Function like this:

const uuid = msg.payload.uuid;
let totals = context.get('totals');
if (! totals) { 
    totals = {};
}
if (totals.hasOwnProperty(uuid)) {
    totals[uuid] += 1;
} 
else {
    totals[uuid] = 1;
}
context.set('totals', totals);
msg.payload = totals;
return msg;
2 Likes

Perfect. Thanks a lot.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.