-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
types: allow defining document array using [{ prop: String }]
syntax
#14095
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, with some questions
Hi @vkarpov15 , today I was updating mongoose and found all the prop values of the schema types became Here's my schema export const UserSchema = new Schema(
{
reminders: {
type: [
{
type: { type: SchemaTypes.String },
date: { type: SchemaTypes.Date },
toggle: { type: SchemaTypes.Boolean },
notified: { type: SchemaTypes.Boolean },
},
],
default: [
{ type: 'vote', date: new Date(), toggle: false, notified: false },
{ type: 'daily', date: new Date(), toggle: false, notified: false },
{ type: 'drop', date: new Date(), toggle: false, notified: false },
{ type: 'claim', date: new Date(), toggle: false, notified: false },
{ type: 'work', date: new Date(), toggle: false, notified: false },
],
},
avatar: {
type: SchemaTypes.String,
},
},
{ timestamps: true },
);
export type IUser = InferSchemaType<typeof UserSchema>; Lemme know if I'm doing anything wrong with the schema. Or if it's a bug, I'll be happy to contribute, lemme me know how can I fix it. If you want me to create a separate issue instead of this comment then also lemme know and I'll create a separate issue. Thanks |
seeing as there has not been a reply and this not being the best place to report this, consider opening a new issue referencing this PR, if this is the problem |
Fix #13424
Summary
In #13424 we noticed that Mongoose doesn't infer
{ type: [{ name: String }] }
as a documentarray, whereas{ type: [new Schema({ name: String })] }
does. This PR fixes that by explicitly looking through the inferred type of the array in the schema and checking against possible definitions liketype: [String]
andtype: [Schema.Types.ObjectId]
.Examples