ts-mongoose icon indicating copy to clipboard operation
ts-mongoose copied to clipboard

Getting OverwriteModelError

Open canaryGrapher opened this issue 2 years ago • 2 comments

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?

canaryGrapher avatar May 06 '22 19:05 canaryGrapher

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

windward-hive avatar Jun 30 '22 19:06 windward-hive

@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 :)

Nikoms avatar Aug 20 '22 22:08 Nikoms