Hi,
I have NR-node-MongoDB that feeds a function "Wrapper" with msg.payload.
Since i am new to NR i am not sure what the first part of the function "Wrapper" does: it uses some filter logic but i cannot find the exact purpose of it
var date=msg.req.params.date;
var enddate = new Date(msg.req.params.date);
enddate.setDate(enddate.getDate()+1);
var dataset = msg.payload.filter(x=>{ return x.startDate < date; });
msg.payload=[dataset[dataset.length-1]].concat(
msg.payload.filter(x=>{return x.startDate==date;})
);
I cannot find the syntax of filter in the NR tutorial. Can anyone pinpoint me to the NR filter function? An url is also okay.
The function you provide to filter is called for each element in the array. If the function returns true, the value is kept. Otherwise it is filtered out.
In this instance, that means dataset ends up being an array of elements whose startDate property is less than date.
It then goes on to set msg.payload to be an array containing the last element of dataset, plus all elements from the original payload whose startDate equals date.