'use strict'; const Schema = require('mongoose').Schema; const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin'); // 群内成员信息 const Patientinfo = new Schema({ patientid: { type: String, required: false }, // 病人ID url: { type: String, required: false }, // 头像url name: { type: String, required: false }, // 病人名称 openid: { type: String, required: false }, // 微信openid }); Patientinfo.index({ patientid: 1 }); // 群信息表 const GroupSchema = { doctorid: { type: String, required: true, maxLength: 500 }, // 医生id列表 name: { type: String, required: false, maxLength: 200 }, // 群名称 content: { type: String, required: false }, // 群简介 patients: { type: [ Patientinfo ], select: false }, // 群里人员信息 }; const schema = new Schema(GroupSchema, { toJSON: { virtuals: true } }); schema.index({ doctorid: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.plugin(metaPlugin); module.exports = app => { const { mongoose } = app; return mongoose.model('Group', schema, 'group'); };