mongo = require("../mongoHelp.js") config = require("../config.js") javalon = require("javalon") function pruneUnpaidAccounts(){ agg = [ {'$match': { timeLimit: { $lt: Date.now()} }}, {'$match': { status: "Inactive" }}] mongo.aggregate(config.database, "users", agg).then(oldArr => { oldArr.forEach(element => { mongo.deleteOne(config.database, "users", {_id:element._id}) }) }) } setInterval(pruneUnpaidAccounts, 3600000)