-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathapp.js
110 lines (85 loc) · 2.49 KB
/
app.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
105
106
107
const mongoose = require('mongoose')
const Student = require('./Student.js')
const db = mongoose.connection;
const mongoURI = 'mongodb://localhost:27017/students';
mongoose.connect(mongoURI, { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false }, () => {
console.log('the connection with mongod is established')
})
const studentsNames = [
'Abdullah Altamimi',
'Abdulrahman Alfouzan',
'Abdulrahman Aljammaz',
'Abdulrahman Alshabibi',
'Abdulwahhab AlBallaa',
'Aisha Dabbagh',
'Dalia Abdullah',
'Fahad Abdullah',
'Hisham Aljahbli',
'Joseph Rulo',
'Lama Alyousef',
'Lamees Alfallaj',
'Mesfer AlQahtani',
'Moayad Alnuwaysir',
'Mohammed Almarri',
'Mohammed Alofaysan',
'Muhannad Alanazi',
'Muneera Bin Hotan',
'Nawal Bin Dawood',
'Noura Albukhaite',
'Nouf Almatroudi',
'Obaid Alqahtani',
'Osama Alruthaya',
'Raje Alharthi',
'Sager Alarifi',
'Sara Alghannamy',
'Sarah Alghofaili',
'Saud Alshamsi',
'Sumayah Ali' ]
const studentsObjects = studentsNames.map(student => { return { name: student } })
// Populate Database with studentsObjects
// Student.insertMany(studentsObjects, (error, student) => {
// if (error) {
// console.log(error)
// } else {
// console.log(student);
// } db.close()
// });
// Print all students names
// Method 1 Print Students Names
// Student.find((err, students) => {
// students.forEach(student => {
// console.log(student.name);
// })
// db.close()
// });
// Method 2 Print Students Object
// Student.find((err, student) => {
// console.log(student);
// db.close()
// });
// Update `Saud Alshamsi` and `Lamees Alfallaj` attendance to false
// Student.findOneAndUpdate({ name: 'Saud Alshamsi' }, { Attendance: false }, (err, student) => {
// if (err) {
// console.log(err);
// } else {
// console.log(student);
// }
// db.close()
// });
// Student.findOneAndUpdate({ name: 'Lamees Alfallaj' }, { Attendance: false }, (err, student) => {
// if (err) {
// console.log(err);
// } else {
// console.log(student);
// }
// db.close()
// });
// Remove 'Joseph Rulo'
// Student.findOneAndRemove({ name: 'Joseph Rulo' }, (err, student) => {
// if (err) {
// console.log(err);
// } else {
// console.log('This is the deleted student:', student);
// }
// db.close()
// });