为了账号安全,请及时绑定邮箱和手机立即绑定

猫鼬模型不会添加为新文档,除非我赋予它唯一的约束

猫鼬模型不会添加为新文档,除非我赋予它唯一的约束

哔哔one 2021-04-26 19:14:18
我有一些需要处理的模型。但是,除非架构中没有唯一属性,否则不会将模型作为文档添加到集合中。这发生在我的本地主机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 }  },我想将模型添加为文档,而不在每个模型中都设置唯一约束。
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 159 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信