'use strict'; const Schema = require('mongoose').Schema; const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin'); const { ObjectId } = require('mongoose').Types; const { Secret } = require('naf-framework-mongoose-free/lib/model/schema'); // 用户表(分站模式) const user = { account: { type: String, required: true }, // 账号 password: { type: Secret, select: false }, // 密码 uid: { type: String }, // 关联id,与各自业务有关的用户id remark: { type: String }, }; const schema = new Schema(user, { 'multi-tenancy': true, toJSON: { virtuals: true } }); schema.index({ id: 1 }); schema.index({ account: 1 }); schema.index({ uid: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.plugin(metaPlugin); module.exports = app => { const { mongoose } = app; return mongoose.model('User', schema, 'user'); };