I'm new to NestJS. I'm sure this is a simple question, but I just can't find the answer.
In the nest docs it recommends having one module per model. This involves creating the model using MongooseModule.forFeature
:
imports: [MongooseModule.forFeature([{ name: 'Cat', schema: CatSchema }])]
The docs say:
If you also want to use the models in another module, add MongooseModule to the
exports
section ofCatsModule
and importCatsModule
in the other module
My question is how to reference the model in the new module.
I can see:
- How this would be done if the model had been created using
mongoose.model('Name', MySchema)
- What exports are needed
- A question that implies this would be done using
import { Model } from 'mongoose'; @InjectModel('name') myModel: Model<MyInterface>)
, but that feel like it repeats the model creation that is done byMongooseModule.forFeature
, because it's combining mongoose Model with the schema again
Any help appreciated!