const mongoose = require('mongoose'); const Schema = mongoose.Schema; const NoticeSchema = new Schema({ title: { type: String, required: true }, content: { type: String, required: true, maxlength: 1000 }, isShow: { type: Boolean, default: true, required: true }, createPerson: String, pv: { type: Number, default: 0, required: true }, meta: { createAt: { type: Date, default: Date.now() }, updateAt: { type: Date, default: Date.now() } } }); NoticeSchema.pre('save', function (next) { if (this.isNew) { this.meta.createAt = this.meta.updateAt = Date.now() } else { this.meta.updateAt = Date.now() } next(); }); module.exports = NoticeSchema;