1234567891011121314151617181920212223242526 |
- 'use strict';
- const Schema = require('mongoose').Schema;
- const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
- const { ObjectId } = require('mongoose').Types;
- const source = 'race';
- // 表
- const ground = {
- name: { type: String, zh: '场地名' },
- remark: { type: String },
- };
- const schema = new Schema(ground, { toJSON: { virtuals: true } });
- schema.index({ id: 1 });
- schema.index({ 'meta.createdAt': 1 });
- schema.plugin(metaPlugin);
- module.exports = app => {
- const is_multiple = app.mongooseDB.clients;
- let model;
- if (is_multiple) {
- const conn = app.mongooseDB.get(source);
- model = conn.model('Ground', schema, 'ground');
- } else {
- const { mongoose } = app;
- model = mongoose.model('Ground', schema, 'ground');
- }
- return model;
- };
|