freeCodeCamp/seed/get-emails.js

26 lines
773 B
JavaScript
Raw Normal View History

2015-06-09 23:49:03 +00:00
/* eslint-disable no-process-exit */
2015-06-05 01:07:00 +00:00
require('dotenv').load();
2015-06-09 23:49:03 +00:00
var secrets = require('../config/secrets'),
mongodb = require('mongodb'),
MongoClient = mongodb.MongoClient;
2015-06-05 01:07:00 +00:00
MongoClient.connect(secrets.db, function(err, database) {
if (err) {
2015-06-09 23:49:03 +00:00
throw err;
2015-06-05 01:07:00 +00:00
}
database.collection('users').aggregate([
{$match: { 'email': { $exists: true } } },
{$match: { 'email': { $ne: '' } } },
{$match: { 'email': { $ne: null } } },
{$match: { 'sendMonthlyEmail': true } },
{$match: { 'email': { $not: /(test|fake)/i } } },
{$group: { '_id': 1, 'emails': {$addToSet: '$email' } } }
], function(err, results) {
2015-06-09 23:49:03 +00:00
if (err) { throw err; }
console.log('\"email\"\n\"' + results[0].emails.join('\"\n\"') + '\"');
2015-06-05 01:07:00 +00:00
process.exit(0);
});
});