Skip to content

Instantly share code, notes, and snippets.

View evancauwenberg's full-sized avatar

Evert Van Cauwenberg evancauwenberg

View GitHub Profile
@evancauwenberg
evancauwenberg / remove_documents_mongodb.js
Created April 11, 2018 14:46 — forked from Stoffo/remove_documents_mongodb.js
Remove Documents older than x days in MongoDB
var date = new Date();
var daysToDeletion = 120;
var deletionDate = new Date(date.setDate(date.getDate() - daysToDeletion));
printjson(deletionDate);
var db = db.getSiblingDB('db')
db.getMongo().setSlaveOk();
printjson(db.messages.find({insertDate : {$lt : deletionDate}}).count());
const path = require('path');
const fs = require('fs');
const { Transform } = require('stream');
const csv = require('fast-csv');
class PersistStream extends Transform {
constructor(args) {
super({ objectMode: true, ...(args || {}) });
this.batchSize = 100;
this.batch = [];