我有一些需要处理的模型。但是,除非架构中没有唯一属性,否则不会将模型作为文档添加到集合中。这发生在我的本地主机mongo和mongo地图集中。每个具有唯一约束属性的模型都将以常规方式添加。没有的每个模型都不会添加。这样编写代码时,一切正常:const UserSchema = new Schema ({ firstName: { type: String, required: [true, "firstName is required"] }, lastName: { type: String, required: [true, "lastName is required"] }, email: { type: String, required: [true, "email is required"], index: { unique: true } }, password: { type: String, required: [true, "password is required"] }, appartments: [{ type: Schema.Types.ObjectId, ref: "appartments" }],})当电子邮件索引属性被注释掉时,该文档将不会出现: email: { type: String, required: [true, "email is required"] //index: { unique: true } },我想将模型添加为文档,而不在每个模型中都设置唯一约束。
添加回答
举报
0/150
提交
取消