-
Notifications
You must be signed in to change notification settings - Fork 1
/
catalogCommonValues.js
34 lines (28 loc) · 1.02 KB
/
catalogCommonValues.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
const mongoose = require('mongoose'),
Mineral = require('./models/Mineral');
CommonValues = require('./models/CommonValues');
mongoose.connect(`mongodb://localhost:27017/mineraldat`);
async function catalogMinerals() {
let commonValues = {};
const minerals = await Mineral.find({});
for (let mineral of minerals) {
for (let key of Object.keys(mineral._doc)) {
if (key !== '_id' && key !== '__v') {
if (!commonValues[key]) {
commonValues[key] = [];
commonValues[key].push(mineral[key]);
} else if (commonValues[key].indexOf(mineral[key]) === -1) {
commonValues[key].push(mineral[key]);
}
}
}
}
for (let category of Object.keys(commonValues)) {
await CommonValues.create({
category: category,
values: commonValues[category]
});
}
mongoose.disconnect()
}
catalogMinerals();