-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
100 lines (91 loc) · 2.44 KB
/
index.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
const express = require('express');
const mongoose = require('mongoose');
const app = express();
const port = 3300;
// Define the Mongoose schema (replace this with your actual schema)
const timetableSchema = new mongoose.Schema({
Teacher: {
Year: {
type: String,
required: true,
},
Department: {
type: String,
required: true,
},
Classname: {
type: String,
required: true,
},
AcademicYear: {
type: String,
required: true,
},
Sem: {
type: String,
required: true,
},
WEF: {
type: String,
required: true,
},
Class: {
type: String,
required: true,
},
RoomNo: {
type: String,
required: true,
},
ClassTeacher: {
type: String,
required: true,
},
Mon: {
type: String,
required: false,
},
Tue: {
type: String,
required: false,
},
Wed: {
type: String,
required: false,
},
Thu: {
type: String,
required: false,
},
Fri: {
type: String,
required: false,
},
Sat: {
type: String,
required: false,
},
},
});
// Define the Mongoose model
const Timetable = mongoose.model('class', timetableSchema);
// Connect to MongoDB
mongoose.connect('mongodb://127.0.0.1:27017/Student', { useNewUrlParser: true, useUnifiedTopology: true });
// Define a route to fetch and print data from the database
app.get('/getTimetableData', async (req, res) => {
try {
// Fetch data from the "classtimetables" collection
const timetableData = await Timetable.find();
// Print the retrieved data in the console
console.log('Timetable Data:', timetableData);
// Send the data as a response (optional)
res.json({ success: true, data: timetableData });
} catch (error) {
console.error('Error fetching data:', error);
res.status(500).json({ success: false, error: 'Internal Server Error' });
}
});
// Start the Express server
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});