I've dedicated a lot of time to researching online, but I can't seem to figure out what's missing in this case. Any help would be greatly appreciated!
Permission.ts (This is the Permission model file. It has references with the Module model via "ModelID")
import mongoose from 'mongoose';
// An interface that outlines the necessary properties
// to create a new User
interface PermissionAttrs {
Code: string;
Name: string;
Description: string;
ModuleID: string;
Active: boolean;
CreatedByUserID: string;
UpdatedByUserID: string;
createdAt: Date;
updatedAt: Date;
}
// Interface describing the properties a User Model has
interface PermissionModel extends mongoose.Model<PermissionDoc> {
build(attrs: PermissionAttrs): PermissionDoc;
}
// Interface describing the properties a User Document has
interface PermissionDoc extends mongoose.Document {
Code: string;
Name: string;
Description: string;
ModuleID: string;
Active: boolean;
CreatedByUserID: string;
UpdatedByUserID: string;
createdAt: Date;
updatedAt: Date;
}
const PermissionSchema = new mongoose.Schema(
{
// Schema definitions here...
});
PermissionSchema.statics.build = (attrs: PermissionAttrs) => {
return new Permission(attrs);
};
const Permission = mongoose.model<PermissionDoc, PermissionModel>(
'Permission',
PermissionSchema
);
export { Permission };
Module.ts (This is the Module model file)
import mongoose from 'mongoose';
// Interfaces and Schema definitions for Module...
ModuleSchema.statics.build = (attrs: ModuleAttrs) => {
return new Module(attrs);
};
const Module = mongoose.model<ModuleDoc, ModuleModel>('Module', ModuleSchema);
export { Module };
This code snippet is used in the route:
import { Permission } from '../models/permission';
...
const Items = await Permission.find()
.populate('ModuleID')
.or(filter || {})
.sort(sort || {})
.skip(start || 0)
.limit(length || 0);
console.log(Items);
Error Message:
“Mongoose error MissingSchemaError: Schema hasn't been registered for model Module”
I've spent all day trying to pinpoint the issue without success. Can someone please point me in the right direction? What am I missing?