The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/private/node_scripts/unsubscribe_csv/unsubscribe.js

62 lines
1.3 KiB

/* eslint import/no-unresolved: 0 */
import lineReader from 'line-reader';
import program from 'commander';
import wait from 'wait.for';
import { MongoClient } from 'mongodb';
program
.usage('[options]')
.option(
'-v, --verbose',
'Verbose',
function (v, total) {
return total + 1;
},
0,
)
.option('-M, --mongo-db [mongo db]', 'Mongo DB', 'localhost:27017')
.option('-N, --db-name [db name]', 'DB Name', 'meteor')
.on('--help', function () {
console.log(' Example:');
console.log('');
console.log(' $ node unsubscribe.js');
return console.log('');
})
.parse(process.argv);
wait.launchFiber(function () {
const db = wait.forMethod(MongoClient, 'connect', `mongodb://${program.mongoDb}/${program.dbName}`, {
replSet: {
socketOptions: {
connectTimeoutMS: 300000,
},
},
});
const User = db.collection('users');
return lineReader.eachLine('./unsubscribe.csv', function (line, last) {
const row = line.split(',');
if (program.verbose) {
console.log(row[0]);
}
return wait.launchFiber(function () {
wait.forMethod(
User,
'update',
{
'emails.address': row[0],
},
{
$set: {
'mailer.unsubscribed': true,
},
},
);
if (last) {
return process.exit();
}
});
});
});