-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseeds.js
58 lines (55 loc) · 1.33 KB
/
seeds.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
var mongoose = require('mongoose');
var Article = require("./models/article.js");
var Rocket = require("./models/rocket.js");
const csvtojson = require("csvtojson");
function seedDB()
{
Article.deleteMany({},function(err)
{
if(err)
{
console.log(err);
}
else
{
csvtojson()
.fromFile("data.csv")
.then(csvData => {
for(var i=0;i<csvData.length;i++)
{
Article.create(csvData[i],function(err, file){
if(err)
{
console.log(err);
}
});
}
});
}
});
Rocket.deleteMany({},function(err)
{
if(err)
{
console.log(err);
}
else
{
csvtojson()
.fromFile("rocket.csv")
.then(csvData => {
for(var i=0;i<csvData.length;i++)
{
Rocket.create(csvData[i],function(err, file){
if(err)
{
console.log(err);
}
});
}
// console.log(csvData);
});
}
});
}
module.exports = seedDB;