ts-mongoose
ts-mongoose copied to clipboard
Getting OverwriteModelError
I keep getting this error when refreshing my Remix application
OverwriteModelError: Cannot overwrite
Forms model once compiled.
This is my model
import { createSchema, Type, typedModel } from 'ts-mongoose';
import { Form1Page1Schema } from './forms/form1page1';
export const FormSchema = createSchema(
{
user: Type.string({ required: true }),
isComplete: Type.boolean({ required: true }),
dateCreated: Type.date({ default: Date.now as any }),
form1page1: Type.object().of(Form1Page1Schema),
}
);
export const Form_Model = typedModel('Form_Data', FormSchema);
How do I fix it?
You can fix it by not using this dead package. It's a remarkable package don't get me wrong, but it's dead. Mongoose has since had significant updates and this needs a lot of work to get it to play nicely with mongoose's latest versions
@maybesmurf @canaryGrapher I had the same problems, so I just made a simple package to infer document type from schema: https://www.npmjs.com/package/mongoose-schema-ts-infer. I hope it will work for you like it worked for me :)