'use strict'; const Schema = require('mongoose').Schema; const moment = require('moment'); const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin'); const { Secret } = require('naf-framework-mongoose/lib/model/schema'); const { ObjectId } = require('mongoose').Types; // 文件链接 const filelinks = new Schema({ title: { type: String, required: false, maxLength: 500 }, // 名称, url: { type: String, required: false, maxLength: 500 }, // 链接地址, }); // 信息表 const news = { user_id: { type: ObjectId }, column_id: { type: String, required: false, maxLength: 500 }, // 栏目id column_name: { type: String, required: false, maxLength: 500 }, // 栏目名称 title: { type: String, required: false, maxLength: 500 }, // 标题 publish_time: { type: String, required: false, maxLength: 500 }, // 时间 origin: { type: String, required: false, maxLength: 500, default: '网站管理员' }, // 来源 brief: { type: String, maxLength: 300 }, // 简介 picture: { type: Object, required: false }, // 图片 filepath: { type: Object, required: false }, // 附件 video: { type: Object }, // 视频 content: { type: String, required: false }, // 正文内容 type: { type: String, required: false, maxLength: 200 }, // 类型,国家,科学院 remark: { type: String, maxLength: 200 }, create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') }, }; const schema = new Schema(news, { toJSON: { virtuals: true } }); schema.index({ id: 1 }); schema.index({ title: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.plugin(metaPlugin); module.exports = app => { const { mongoose } = app; return mongoose.model('News', schema, 'news'); };