我有一个关于如何在 NestJS 上为 Mongoose 集合中的字段建立索引的问题。 以下示例中的索引方法是否正确完成? 我是否必须在架构级别将 autoindex 字段值设置为 false,然后在要建立索引的字段级别将索引值设置为 true?
@Schema({ timestamps: true, autoIndex: false })
export class Ticket {
@Prop({ required: true, index: true })
title: string;
@Prop({ required: true, index: true })
name: string;
@Prop({ type: ContactModelSchema })
contact: ContactModel;
@Prop({ type: ContentModelSchema, index: true })
acceptedContent: ContentModel;
}
export const TicketSchema = SchemaFactory.createForClass(Ticket);
@Schema({ timestamps: true, _id: false, autoIndex: false })
export class ContentModel {
@Prop()
websiteUrl: string;
@Prop({ index: true })
body: string;
@Prop()
galleryUrls: [string];
@Prop()
voiceUrl: string;
@Prop({ type: VideoModelSchema })
video: VideoModel;
@Prop({ type: [String], index: true })
tags: string[];
@Prop({ type: LocationModelSchema, index: true })
location: LocationModel;
}
export const ContentModelSchema = SchemaFactory.createForClass(ContentModel);