-
Notifications
You must be signed in to change notification settings - Fork 3
/
export.js
49 lines (41 loc) · 1.04 KB
/
export.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const collectionName = 'REG_DATA-TR17_EMAIL_ADDRESSES';
const fs = require('fs');
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
var sha256 = require('js-sha256');
var db = null,
client = null;
// Use connect method to connect to the server
MongoClient.connect(process.env.mongoURL, function (err, _client) {
assert.equal(null, err);
client = _client;
db = client.db(process.env.dbName);
processor();
});
var processor = (index) => {
getEmails()
.then((documents) => {
var json = JSON.stringify(documents);
fs.writeFileSync('./email/db.json', json);
client.close();
})
}
var getEmails = (index) => {
return new Promise((resolve, reject) => {
db.collection(collectionName)
.distinct(
'CR17_EMAIL', {
'CR17_EMAIL' : {
$exists: true,
$ne: null
}
},function (error, response) {
if(error)
return reject(error);
resolve(response.map(x => sha256(x)));
});
})
}
process.on('beforeExit', () => {
console.log('exiting')
})