Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
newrelic.startBackgroundTransaction('collect:clearCollections', function transactionHandler() {
const transaction = newrelic.getTransaction();
let dtlw = new Date(Date.now() - ctx.cfg.app.cleanRetention);
let q = { _dt: { $lte: dtlw } };
let collectionsToClear = ['page_errors', 'pages', 'page_reqs', 'actions', 'action_stats', 'action_errors', 'metrics'];
safe.each(collectionsToClear, async ctc => {
await collections[ctc].deleteMany(q);
/* const { deletedCount } = */ await collections[ctc].deleteMany(q);
/*
if (deletedCount > 0)
console.info('cleaned %d documents in collection %s at %s', deletedCount, ctc, new Date());
*/
}, err => {
if (err)
newrelic.noticeError(err);
transaction.end();
});
});