-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtestdb.js
More file actions
40 lines (37 loc) · 1.32 KB
/
testdb.js
File metadata and controls
40 lines (37 loc) · 1.32 KB
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
const BlacklistIDModel = require('./models/blacklistidmodel');
const config = require('./config.json')
const mongoose = require('mongoose');
const fs = require('fs');
var configids = config.blacklistedids;
var blacklistedids = []
mongoose.connect('mongodb://' + config.db.user + ':' + config.db.pass + '@' +'localhost/nogiveaway', function (err) {
if (err) throw err;
BlacklistIDModel.find({}, function(err, data){
if(err){
console.log(err);
};
if(data.length == 0) {
console.log("nothing gotten")
}
for(var i=0;i<data.length;i++){
if(data[i].userid.length == 1){
blacklistedids.push(parseFloat(data[i].userid.toString()));
}
else{
blacklistedids = blacklistedids.concat(data[i].userid);
}
}
saveblacklist()
});
}, {useNewUrlParser: true});
function saveblacklist(){
blacklistedids.concat(configids)
blacklistedids = [...new Set(blacklistedids)];
fs.writeFile("outputx.json", JSON.stringify({blacklistedids:blacklistedids},null, 4), 'utf8', function (err) {
if (err) {
console.log("An error occured while writing JSON Object to File.");
return console.log(err);
}
console.log("JSON file has been saved.");
});
}