Created
December 8, 2023 08:45
-
-
Save Lahirutech/ebd5a17d56343db690b263865812a6dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Document, Model } from "mongoose"; | |
import * as Mongoose from "mongoose"; | |
const postSchema = new Mongoose.Schema({ | |
name: { | |
type: String, | |
required: true, | |
}, | |
}); | |
interface IPost { | |
name: string; | |
} | |
interface IPostDocument extends IPost, Document {} | |
interface IPostModel extends Model<IPostDocument> {} | |
// Model export that creates error | |
// const PostModel: IPostModel = Mongoose.model<IPostDocument>("post", postSchema); | |
//Solution | |
const PostModel: IPostModel = | |
Mongoose.models.post || Mongoose.model<IPostDocument>("post", postSchema); | |
export default PostModel; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment