lecture.js 1.09 KB
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);