You need every second to save the number in mongo. How to implement it?
Wrote a simple function:
function test_save(){
var item = new Testmodel({
data: 123
});
item.save(function(err, item){
if(err)throw(err);
setTimeout(test_save, 1000);
});
}
Tried to keep using setInterval/setTimeout, it works, but memory leak occurs due to which then all the worse. They can clean the setTimeout, while recording?
Or maybe there's something radically different that will help me to Periodically run the function without leaking memory?