-
Notifications
You must be signed in to change notification settings - Fork 25
/
cleanupInvalidTags.js
99 lines (84 loc) · 2.99 KB
/
cleanupInvalidTags.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Retrieve
var MongoClient = require('mongodb').MongoClient;
var ObjectId = require('mongodb').ObjectID;
// Connect to the db
// Dev
// MongoClient.connect("mongodb://x:x@localhost:5555/epic", async function(err, client) {
// Test
// MongoClient.connect("mongodb://x:x@localhost:5555/epic", async function(err, client) {
// Local
MongoClient.connect('mongodb://localhost/epic', async function(err, client) {
if (!err) {
console.log('We are connected');
const db = client.db('epic');
let typeData = require(process.cwd() + '/null_type');
console.log('typeData:', typeData.length);
let projectPhaseData = require(process.cwd() + '/null_projectPhase');
console.log('projectPhaseData:', projectPhaseData.length);
let authorData = require(process.cwd() + '/null_author');
console.log('authorData:', authorData.length);
let milestoneData = require(process.cwd() + '/null_milestone');
console.log('milestoneData:', milestoneData.length);
const typePromises = [];
for (let z = 0; z < typeData.length; z++) {
let object_id = typeData[z]._id.substring(9,33);
typePromises.push(updateType(db, ObjectId(object_id)));
}
const projectPromises = [];
for (let z = 0; z < projectPhaseData.length; z++) {
let object_id = projectPhaseData[z]._id.substring(9,33);
projectPromises.push(updateProjectPhase(db, ObjectId(object_id)));
}
const authorPromises = [];
for (let z = 0; z < authorData.length; z++) {
let object_id = authorData[z]._id.substring(9,33);
authorPromises.push(updateAuthor(db, ObjectId(object_id)));
}
const milestonePromises = [];
for (let z = 0; z < milestoneData.length; z++) {
let object_id = milestoneData[z]._id.substring(9,33);
milestonePromises.push(updateMilestone(db, ObjectId(object_id)));
}
await Promise.all([projectPromises, authorPromises, milestonePromises, typePromises]);
console.log('ALL DONE');
client.close();
} else{
console.log(err);
}
});
async function updateType(db, object_id) {
return new Promise(function(resolve) {
db.collection('epic')
.updateOne({ _id: object_id },{ $set: { type: null }})
.then(async function(data) {
resolve(data);
});
});
}
async function updateProjectPhase(db, object_id) {
return new Promise(function(resolve) {
db.collection('epic')
.updateOne({ _id: object_id },{ $set: { projectPhase: null }})
.then(async function(data) {
resolve(data);
});
});
}
async function updateMilestone(db, object_id) {
return new Promise(function(resolve) {
db.collection('epic')
.updateOne({ _id: object_id },{ $set: { milestone: null }})
.then(async function(data) {
resolve(data);
});
});
}
async function updateAuthor(db, object_id) {
return new Promise(function(resolve) {
db.collection('epic')
.updateOne({ _id: object_id },{ $set: { documentAuthorType: null }})
.then(async function(data) {
resolve(data);
});
});
}