lecture.js
1.09 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
const mongoose = require('mongoose');
const LectureSchema = new mongoose.Schema({
lecturename: { type: String, required: true, unique: true }
});
// // Create new review document
LectureSchema.statics.create = function (payload) {
// this === Model
const review = new this(payload);
// return Promise
return review.save();
};
// Find All
LectureSchema.statics.findAll = function () {
// return promise
// V4부터 exec() 필요없음
return this.find({});
};
// Find One by lecturename
LectureSchema.statics.findOneBylecturename = function (lecturename) {
return this.findOne({ lecturename });
};
// Update by lecturename
LectureSchema.statics.updateBylecturename = function (lecturename, payload) {
// { new: true }: return the modified document rather than the original. defaults to false
return this.findOneAndUpdate({ lecturename }, payload, { new: true });
};
// Delete by lecturename
LectureSchema.statics.deleteBylecturename = function (lecturename) {
return this.remove({ lecturename });
};
// Create Model & Export
module.exports = mongoose.model('Lecture', LectureSchema);