-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimportCSV.js
42 lines (36 loc) · 909 Bytes
/
importCSV.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
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/newEmails');
var csv = require('csv-parser')
var fs = require('fs')
var Schema = mongoose.Schema;
var SCEmailsSchema = new Schema({
email: {
type: String,
unique: true
},
numTracks: Number,
artist: Boolean,
soundcloudID: Number,
soundcloudURL: String,
username: String,
followers: Number,
randomDay: Number,
scanned: Boolean
});
var SCEmails = mongoose.model('scemails_with_members', SCEmailsSchema);
var db = mongoose.connection;
db.on('error', function(err) {
console.log('connection error', err);
});
db.once('open', function() {
console.log('connected.');
fs.createReadStream('unsubscribed_export.csv')
.pipe(csv())
.on('data', function(data) {
SCEmails.findOne({
email: data["Email Address"]
}).then(function(email) {
email.remove();
});
})
});