'use strict'; const Schema = require('mongoose').Schema; const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin'); const { Secret } = require('naf-framework-mongoose/lib/model/schema'); // 用户表 const UserSchema = { name: { type: String, required: false, maxLength: 200 }, // 名称 mobile: { type: String, required: true, maxLength: 64 }, // 手机 passwd: { type: Secret, select: false }, // 注册密码 openid: { type: String, required: false }, // 微信openid remark: { type: String, required: false }, // 备注 }; const schema = new Schema(UserSchema, { toJSON: { virtuals: true } }); schema.index({ openid: 1 }); schema.index({ mobile: 1 }); schema.plugin(metaPlugin); module.exports = app => { const { mongoose } = app; return mongoose.model('User', schema, 'user'); };