forked from bunyaminsari/deviceApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseeds.js
More file actions
82 lines (75 loc) · 1.75 KB
/
seeds.js
File metadata and controls
82 lines (75 loc) · 1.75 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Mongoose Connection
const mongoose = require('mongoose');
// Importing Device Model
const Device = require('./models/device');
mongoose.connect('mongodb://localhost:27017/deviceApp')
.then(() =>{
console.log('CONNECTION OPEN')
})
.catch(err => {
console.log('OH NO! WE MESSED UP!')
console.log(err)
})
// We have just copied above part of the code that, to seed the database. It does not have any relation with
// the app, it is something we want to play with the database.
// This is for adding a single device to the database. It worked.
// const d = new Device({
// product:'Chromebook',
// make:'Lenovo',
// model:'N23',
// serial:'lr08wr9e',
// barcode: 200222,
// price:200,
// category:'stock'
// })
// d.save().then(d =>{
// console.log(d)
// })
// .catch(e =>{
// console.log(e)
// })
// Lets insert more devices to the database.
const seedDevices = [
{
product:'iPad',
make:'Apple',
model:'Air',
serial:'kdka7798798',
barcode: 200021,
price:300,
category:'mobile'
},
{
product:'Smartboard',
make:'Smart',
model:'K64',
serial:'jdkadkadk788',
barcode: 200233,
price:800,
category:'fixed'
},
{
product:'Chromebook',
make:'Lenovo',
model:'N22',
serial:'lr08wr9e',
barcode: 200233,
price:100,
category:'junk'
},
{
product:'Laptop',
make:'Dell',
model:'Inspiron',
serial:'lr08dadadadwr9e',
barcode: 200333,
price:50,
category:'donate'
}
]
Device.insertMany(seedDevices).then(res=>{
console.log(res)
})
.catch(e =>{
console.log(e)
})