-
So I have a Booking object as such: export class Booking {
@Field(() => String)
readonly _id: string | mongoose.Types.ObjectId;
/* ------------------------------ Time metadata ----------------------------- */
@Field(() => Date)
@Property({ required: true, index: true })
startTime: Date;
@Field(() => Date)
@Property({ required: true, index: true })
endTime: Date;
@Field(() => [User])
@Property({ type: [User], required: true, default: [], index: true })
bookableUsers: User[];
@Field(() => [Bookable])
@Property({ type: [Bookable], required: true, default: [], index: true })
bookables: Bookable[];
} Do I have to specify a specific field (_id in this case) for the array subdocuments (bookableUsers & bookables) in this case? According to the docs: https://www.mongodb.com/docs/manual/core/index-multikey/ -> "MongoDB automatically creates a multikey index if any indexed field is an array; you do not need to explicitly specify the multikey type." If I do need to specify the field, how could I do so? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
@hasezoey Also on another note: syncIndexes() also creates indexes for nested documents. For example: Location has a unique field called name, typegoose will create the index for location.name to be unique within the Booking collection. Is this a bug or desired behavior? Doesn't make sense for Location's unique indecies to be carried over when it's used as a nested document |
Beta Was this translation helpful? Give feedback.
-
I think this was brought up in 2020 by @rubenvereecken: Automattic/mongoose#9128 and szokodiakos/typegoose#407 . I can't seem to find the issue in the new repo |
Beta Was this translation helpful? Give feedback.
-
Seems like excludeIndexes: true is the answer! |
Beta Was this translation helpful? Give feedback.
Seems like excludeIndexes: true is the answer!