-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Make foo: { type: { name: String } }
behave the same as { foo: new Schema({ name: String }) }
#7181
Comments
I agree with this change @vkarpov15. I can't think of a reason why anyone would create a new mixed path like this on purpose. |
Wait... so declaring a schema like in this example: |
@mhombach no, in that example you get a document array. Examples: // With below, `parent` will **not** be mixed or array of mixed
parent: { child1: { type: String, required: true }, child2: { type: String, required: true } }
parent: [{ type: { child1: { type: String, required: true }, child2: { type: String, required: true } } }]
// With the below, `parent` will be mixed
parent: { type: { child1: { type: String, required: true }, child2: { type: String, required: true } } } In other words, this issue only impacts you if you declare a nested path using |
This really makes sense especially for developers using TypeScript. This type definition is very common in TS so this can avoid confusion. |
foo: { type: { name: String } }
behave the same as { foo: { name: String } }
foo: { type: { name: String } }
behave the same as { foo: new Schema({ name: String }) }
…g }` create a single nested subdoc, remove `typePojoToMixed` because it is now always false Fix #7181
Re: #7143. Right now the below declarations are different, and its a very subtle footgun that's hard to notice.
Demo using Node shell:
Anybody have thoughts on this? I'm thinking it makes sense to deprecate this behavior, and make it so that
new Schema({ foo: { type: { name: String } } })
makesfoo.name
a string in Mongoose 6.x.@lineus @Fonger ?
The text was updated successfully, but these errors were encountered: