I need to publish the stats from my CPU, Memory and other things that are stored in a collection. The things is it need to publish only the 10 last seconds from now.
I join a picture to help the understanding of this:
And I coded a function but the problem is that it doesn't remove the infos that are 11sec,12sec... older than now.
Meteor.publish('dockerStats', function readInfosDockerStats(timeLimitSecond) {
console.log(moment(new Date()).subtract(timeLimitSecond, 'second').toDate())
return DockerStats.find(
{ read: { "$gte": moment(new Date()).subtract(timeLimitSecond, 'second').unix()} },
);
I think I need to use $and
and to find infos that are
>now-10sec && <now
But I don't know how to make it so I'm asking for your help.
[EDIT] I added the $and
the only problem is that it publish only 1time (the infos keep being writing in the collection but it doesn't publish them):
Meteor.publish('dockerStats', function readInfosDockerStats(timeLimitSecond) {
return DockerStats.find(
{ $and: [{ read:{"$gte": moment(new Date()).subtract(timeLimitSecond, 'second').unix()}},{read:{"$lte": moment(new Date()).unix()}}]
})
});