-
Notifications
You must be signed in to change notification settings - Fork 1
/
db.js
105 lines (88 loc) · 1.81 KB
/
db.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const mongoose = require("mongoose");
mongoose
.connect(process.env.MONGO_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(function () {
console.log("connected to bankDB");
})
.catch((err) => console.error(err));
//schema for user
const userSchema = new mongoose.Schema({
name: String,
email: String,
balance: Number,
});
//make model
const User = mongoose.model("User", userSchema);
const user1 = new User({
name: "Atul kumar",
email: "[email protected]",
balance: 3000,
});
const user2 = new User({
name: "Alok kumar",
email: "[email protected]",
balance: 6700,
});
const user3 = new User({
name: "Chandan kumar",
email: "[email protected]",
balance: 3800,
});
const user4 = new User({
name: "Chandrama kumar",
email: "[email protected]",
balance: 1200,
});
const user5 = new User({
name: "Ankita kumari",
email: "[email protected]",
balance: 3000,
});
const user6 = new User({
name: "Subodh kumar",
email: "[email protected]",
balance: 3900,
});
const user7 = new User({
name: "Ashwani kumar",
email: "[email protected]",
balance: 3000,
});
const user8 = new User({
name: "Harsh kumar",
email: "[email protected]",
balance: 1000,
});
const user9 = new User({
name: "Pranav kumar",
email: "[email protected]",
balance: 9800,
});
const user10 = new User({
name: "Sushant kumar",
email: "[email protected]",
balance: 6700,
});
const userData = [
user1,
user2,
user3,
user4,
user5,
user6,
user7,
user8,
user9,
user10,
];
User.find().then((foundItems) => {
if (foundItems.length == 0) {
User.insertMany(userData)
.then(() => console.log("inserted dummy data"))
.catch((err) => console.error(err));
}
})
.catch((err) => console.error(err));