I'm using mongoDB database and using typegoose and mongoose. I have this file with the code below and I'm getting the error TypeError: Right-hand side of 'instanceof' is not an object on the last line where I call getModelForClass(UserClass). I've looked for hours and can't figure out how to get rid of this error. There is no circular reference as I've read it could be the issue. Any help would be appreciated.
import { ModelOptions, Severity, getModelForClass, index, post, prop } from '@typegoose/typegoose';
import mongoose from 'mongoose';
@post<UserClass>('save', function (doc) {
if (doc) {
doc.id = doc._id.toString();
doc._id = doc.id;
}
})
@post<UserClass[]>(/^find/, function (docs) {
// @ts-ignore
if (this.op === 'find') {
docs.forEach((doc) => {
doc.id = doc._id.toString();
doc._id = doc.id;
});
}
})
@ModelOptions({
schemaOptions: {
timestamps: true,
collection: 'users',
},
options: {
allowMixed: Severity.ALLOW,
},
})
@index({ username: 1 })
class UserClass {
@prop({ required: true, unique: true })
public username: string;
@prop({ required: true })
public firstName: string;
@prop({ required: true })
public lastName: string;
@prop({ required: true })
public hash: string;
_id: mongoose.Types.ObjectId | string;
id: string;
}
export const User = getModelForClass(UserClass);