'use strict'; const Schema = require('mongoose').Schema; const moment = require('moment'); const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin'); const { ObjectId } = require('mongoose').Types; // 问卷题目表 const question = { title: { type: String }, type: { type: String }, // 类型:0=>单选;1=>多选;2=>简答 selects: { type: Array }, // 选项 user_id: { type: ObjectId }, // 所属用户 remark: { type: String, maxLength: 200 }, create_time: { type: String, default: moment(new Date()).format('YYYY-MM-DD HH:mm:ss') }, }; const schema = new Schema(question, { toJSON: { virtuals: true } }); schema.index({ id: 1 }); schema.index({ title: 1 }); schema.index({ user_id: 1 }); schema.index({ type: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.plugin(metaPlugin); module.exports = app => { const { mongoose } = app; return mongoose.model('Question', schema, 'question'); };