0
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { Document, Schema as MongooseSchema, model } from "mongoose";

export type BookDocument = Book & Document;

@Schema()
export class Book {
  _id: MongooseSchema.Types.ObjectId;

  @Prop({ required: true, unique: true })
  name: string;
}

export const BookSchema = SchemaFactory.createForClass(Book);

export const BookModel = model<BookDocument>("Book", BookSchema);

Here, using mongoose version 6.0.2 & BookSchema is giving error. But in version 5.0.2 it is working file. @nesjs/mongoose version in 9.2.1 . What is the issue behind this version changes?

Expected BookSchema will work perfectly for mongoose version 6

  • What is the error? – NeNaD Dec 29 '22 at 07:33
  • Type 'Schema, {}, {}, {}, {}, DefaultSchemaOptions, Book>' is not assignable to type 'Schema'. The types of 'obj._id' are incompatible between these types. –  Dec 29 '22 at 07:40

0 Answers0