I am building Node.js scripts that will be ran as CRON jobs. (full terminal scripts). These scripts fetch data from all around using APIs and MongoDB (native driver) is used. I don't didn't use db.close()
statement and because of that script will never end by itself (or at least it looks like that way from the terminal), to finish it, it is necessary to press CTRL+C to cancel.
Back then when I was writing these scripts, someone from Stack overflow told me that it is not required to close connection anyway. So I let it be.
Now I wonder, do these scripts actually are still running? And as these would be ran as CRON jobs, with small intervals, does that mean that these scripts will eventually kill RAM from the server? Does that mean, there will be thousands scripts running and waiting for db.close()
statement?
Example code:
MongoClient.connect(mongoUrl, (err, db) => {
if (err) {
console.log(err);
return;
}
var usersCollection = db.collection('users').find();
usersCollection.on('data', (doc) => {
console.log(doc);
});