'use strict'; const Schema = require('mongoose').Schema; const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin'); const { ObjectId } = require('mongoose').Types; // 题目表 const question = { title: { type: String }, // 题目 type: { type: String }, // 类型 selects: { type: Array }, // 选项: {label,value,isRight:Boolean, true:正确/false:错误} remark: { type: String }, times: { type: Number, default: 0 }, // 出题次数 }; const schema = new Schema(question, { toJSON: { virtuals: true } }); schema.index({ id: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.plugin(metaPlugin); module.exports = app => { const { mongoose } = app; return mongoose.model('Question', schema, 'question'); };