nestjs / mongoose

Mongoose module for Nest framework (node.js) 🍸
https://nestjs.com
MIT License
528 stars 118 forks source link

TypeError: Invalid schema configuration: `True` is not a valid type at path `view.require`. See http://bit.ly/mongoose-schematypes for a list of valid schema types. #397

Closed AkpoFlash closed 4 years ago

AkpoFlash commented 4 years ago

I'm submitting a...


[ ] Regression 
[X] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

When I want to describe my schemas like this:

import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';

@Schema()
export class Article extends Document {
  @Prop({ require: true })
  title: string;

  @Prop()
  author: string;

  @Prop()
  body: string;

  @Prop()
  hidden: boolean;
}

export const ArticleSchema = SchemaFactory.createForClass(Article);

Then I execute

nest start

and I have this error message:

TypeError: Invalid schema configuration: `True` is not a valid type at path `view.require`. See http://bit.ly/mongoose-schematypes for a list of valid schema types.

Expected behavior

Run/build the project without this error

Environment


Nest version: 7.1.2

For Tooling issues:
- Node version: 14.2.0
- Platform:  Mac
kamilmysliwiec commented 4 years ago

"require" is invalid. Use "required" instead.

AkpoFlash commented 4 years ago

Yes, of course, "require" is invalid. I use "required" in my code, but just did the mistake when wrote code here. Sorry for this.

Anyway, I have the same error:

TypeError: Invalid schema configuration: `True` is not a valid type at path `title.required`. See http://bit.ly/mongoose-schematypes for a list of valid schema types.

Also, I have the same error with any default value, for example:

  @Prop({ default: 1 })
  views: number;

error:

TypeError: Invalid schema configuration: `1` is not a valid type at path `views.default`. See http://bit.ly/mongoose-schematypes for a list of valid schema types.
AkpoFlash commented 4 years ago

This problem still relevant, maybe you reopen the issue?

elizabeth-dev commented 4 years ago

+1, same problem here.

kamilmysliwiec commented 4 years ago

Please, use our Discord channel (support) for such questions.

If you're getting this error, it means you're passing the invalid property options to the @Prop() decorator. Make sure your @nestjs/mongoose version is 7.0.1 (the latest published one). I've just tested both default and required options and it works properly.

kamilmysliwiec commented 4 years ago

I've updated the sample/06-mongoose in the nestjs repo to use the latest version as well (just in case)