【发布时间】:2022-11-10 04:46:05
【问题描述】:
我想将我的 express api 中的猫鼬模式转换为嵌套 js。
const levelSchema = new Schema(
{
title: {
type: String,
required: true,
},
},
{
timestamps: true,
}
);
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
export type LevelDocument = Level & Document;
@Schema({
timestamps: true,
})
export class Level {
@Prop({
type: [
{
locale: { type: String, enum: ["fr", "en"] },
title: { type: String, unique: true },
},
],
})
translations: object[];
@Prop({ default: false })
visibility: Boolean;
}
export const LevelSchema = SchemaFactory.createForClass(Level);
它按预期工作,但由于某种原因我无法为标题添加唯一键?我没有任何错误,它似乎只是忽略了unique: true 规则。
【问题讨论】: