-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mongoose casts wrong data type on property with options and type
property
#11199
Comments
Could you please provide all the code to reproduce this issue. I am having a hard time attempting to reproduce based on a block of code and screenshots. |
Hi @IslandRhythms, Here the repo with reproduction. https://github.com/Cartman720/nestjs-mongoose-bug With NestJS team we could find out that whenever we provide |
@Cartman720 we took a look and the workaround is the same as in #10807 (comment) . Replace BlogArticleSchema.loadClass(BlogArticle);
// @ts-ignore
delete String.type; We added a workaround and the fix will be in v6.1.8. However, we still recommend doing |
Opened an issue with nestjs/mongoose about this |
Do you want to request a feature or report a bug?
bug
What is the current behavior?
I am using
@nestjs/mongoose
class schema definition, However when I retrieve document from database, mongoose converts values such asstring
,number
toDocument
.On above schem you can see that
content
property is astring
withdefault
property.However you can see on the screenshot of VSCode debugger, that retrieved data is a ``Document
object, hence I can't use JS built-in string methods i.e.
match`, `split` etc.I have debugged
@nestjs/mongoose
SchemaFactory
and did found that it creates valid Mongose schema, so I don't think this is related to external package, rather it's a bug in mongoose itself.Attaching debugger screenshot for
SchemaFactory
.But when I set
@Prop(String)
to `content property I get valid string, howerver this isn't viable for my case, because I want to use mongoose options for properties.What is the expected behavior?
I would expect to get string value with option
@Prop({ type: String, default: '' })
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Mongoose: 6.1.5
Mongo: 4.4
The text was updated successfully, but these errors were encountered: