0

我有条件地有 12 个集合(按月),文档架构是相同的。为了不写不必要的代码,我尝试这样做:

import { pre } from 'typegoose';

import { BaseSchema } from './baseSchema';


export class ItemSchema extends BaseSchema {
    // options
}

export const Item01 = new ItemSchema().getModelForClass(ItemSchema, {
     schemaOptions: {collection: 'Item01'}
}); // January

export const Item02 = new ItemSchema().getModelForClass(ItemSchema, 
     {schemaOptions: {collection: 'Item02'}
}); // February
...
export const Item05 = new ItemSchema().getModelForClass(ItemSchema, 
     {schemaOptions: {collection: 'Item05'}
}); // May

我向集合 05 发出请求,但它总是转到 01

// destination import 
import * as ItemModels from '../../ItemModel';
const items = await ItemModels.Item05.find()

我真的不想像往常一样画这12个系列,这样的“短”版真的不合适吗?

我将不胜感激您的帮助!祝你今天过得愉快!

4

0 回答 0