-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_collection.js
111 lines (92 loc) · 3.05 KB
/
load_collection.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
100
101
102
103
104
105
106
107
108
109
110
111
function loadEducations() {
const bulkInsert = db.educations.initializeUnorderedBulkOp();
const documents = db.full.find({});
documents.forEach(function (doc) {
const element = {
education: doc.education,
education_num: doc.education_num
};
bulkInsert.find(element).upsert().replaceOne(element);
});
bulkInsert.execute();
return true;
}
function loadOccupations() {
const bulkInsert = db.occupations.initializeUnorderedBulkOp();
const documents = db.full.find({});
documents.forEach(function (doc) {
const element = {
occupation: doc.occupation,
workclass: doc.workclass,
hours_per_week: doc.hours_per_week
};
bulkInsert.find(element).upsert().replaceOne(element);
});
bulkInsert.execute();
return true;
}
function loadRelationships() {
const bulkInsert = db.relationships.initializeUnorderedBulkOp();
const documents = db.full.find({});
documents.forEach(function (doc) {
const element = {
marital_status: doc.marital_status,
relationship: doc.relationship
};
bulkInsert.find(element).upsert().replaceOne(element);
});
bulkInsert.execute();
return true;
}
function loadFinances() {
const bulkInsert = db.finances.initializeUnorderedBulkOp();
const documents = db.full.find({});
documents.forEach(function (doc) {
const element = {
total: doc.total,
capital_gain: doc.capital_gain,
capital_loss: doc.capital_loss,
income_bracket: doc.income_bracket
};
bulkInsert.find(element).upsert().replaceOne(element);
});
bulkInsert.execute();
return true;
}
function loadUsers() {
const bulkInsert = db.users.initializeUnorderedBulkOp();
const documents = db.full.find({});
documents.forEach(function (doc) {
const userElement = {
age: doc.age,
gender: doc.gender,
race: doc.race,
native_country: doc.native_country
};
const education = db.educations.findOne({
education: doc.education
});
userElement.education_id = education._id;
const occupation = db.occupations.findOne({
occupation: doc.occupation,
workclass: doc.workclass,
hours_per_week: doc.hours_per_week
});
userElement.occupation_id = occupation._id;
const finance = db.finances.findOne({
total: doc.total,
capital_gain: doc.capital_gain,
capital_loss: doc.capital_loss,
income_bracket: doc.income_bracket
});
userElement.finance_id = finance._id;
const relationship = db.relationships.findOne({
marital_status: doc.marital_status,
relationship: doc.relationship
});
userElement.relationship_id = relationship._id;
bulkInsert.find(userElement).upsert().replaceOne(userElement);
});
bulkInsert.execute();
return true;
}