-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddDataToTracts.js
More file actions
59 lines (48 loc) · 1.64 KB
/
addDataToTracts.js
File metadata and controls
59 lines (48 loc) · 1.64 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require('dotenv').config();
const mongoose = require("mongoose");
const db = require("./models");
const csvToJson = require('convert-csv-to-json')
const MONGODB_URI = process.env.MONGODB_URI;
const dataPath = './data/All_CensusTract2010_2022.csv';
const collection = 'tractInfo';
const dataArray = csvToJson.fieldDelimiter(',').getJsonFromCsv(dataPath);
const run = async () => {
await mongoose
.connect(
MONGODB_URI,
{
useNewUrlParser: true,
useUnifiedTopology: true
}
)
.then(() => console.log('Connection successful'))
.catch(err => {throw err});
for await (obj of dataArray){
const suppress = false; // new Number(obj.TotalTransactionsWithSalePrice2022) <= 10;
console.log(obj.geo, suppress ? '🚫' : '✅');
await db[collection].findOneAndUpdate({GEOID: obj.geo}, { $set : {
"Data.Aggregate Home Sales, 2022": !suppress ? new Number(obj.GrossMaxSalePrice2022) : '',
"Data.Aggregate Building Area of Home Sales, 2022": !suppress ? new Number(obj.GrossBuildingAreaInferred2022) : ''
}})
// await db[collection].updateOne({GEOID: obj.GEOID}, { Data: {
// ['Aggregate Home Sales, 2022']: obj.AggregateHomesSales},
// ['Aggregate Building Area of Home Sales, 2022']: obj.AggregateBuildingAreaofHomesSales
// }, (err) => console.log(err));
// i++
// }
// }
// )
}
};
run()
.then(() => process.exit(0))
.catch(() => console.log(err));
// db[collection].update({})
// .then(data => {
// console.log(data.length + " records inserted!");
// process.exit(0);
// })
// .catch(err => {
// console.error(err);
// process.exit(1);
// })