Populate in Mongoose doesn't work if I'm using Typescript Error: Schema hasn't been registered for model "Category" #15260
Labels
help
This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
Prerequisites
Mongoose version
8.9.1
Node.js version
22.14.0
MongoDB server version
6.12.0
Typescript version (if applicable)
5
Description
I'm using NextJs 15 with TypeScript and Mongoose, but when I try to populate the Product fields with the category, I get the following error: Error: Schema hasn't been registered for model "Category". Use mongoose.model(name, schema). Also I've realized that if I comment out
.populate()
and then add it back when the server is already running, it works perfectly. So seems the problem is at the moment of compiling code.Steps to Reproduce
This is the Product Schema:
This is my category Schema:
and this is my use case:
Expected Behavior
No response
The text was updated successfully, but these errors were encountered: