-
Notifications
You must be signed in to change notification settings - Fork 1
/
addToDb.js
35 lines (30 loc) · 911 Bytes
/
addToDb.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
require('dotenv').config();
const mongoose = require('mongoose');
const fs = require('fs');
const moment = require('moment');
const JobList = require('./src/models/Job');
// console.log(process.env);
const dbUrl = process.env.DB_HOST;
console.log(dbUrl);
mongoose.connect(dbUrl, { useNewUrlParser: true })
.then(() => {
console.log('Database connected');
addData();
})
.catch(err => console.log(err));
function addData() {
let data = JSON.parse(fs.readFileSync('output.json', 'utf-8'));
let insert_data = data.map((elem) => {
temp = elem.posted_date.split(" ");
elem.posted_date = moment().subtract(parseInt(temp[0]), temp[1]).toDate();
elem.is_notified = true;
return elem;
});
JobList.insertMany(insert_data).then((err,docs)=>{
if(err){
console.log(err);
}
console.log(docs);
mongoose.disconnect();
})
}