【发布时间】:2021-02-11 00:31:47
【问题描述】:
在下面的代码中,注释的电子邮件模式是以前的,我不再希望电子邮件是必需的,并且是唯一的,它应该是可选的。
我收到一个错误,说重复,null "E11000 重复键错误集合:mydb.lists index: email_1 dup key: (email: null)"
const mongoose = require("mongoose");
const { Schema } = mongoose;
const alliedSchema = new Schema(
{
name: String,
phone: String,
email: {
unique: false,
type: String
},
// email:{
// type: String,
// unique: true,
// required: true,
// lowercase: true,
// validate(value){
// if(!validator.isEmail(value)){
// throw new Error('Email is invalid')
// }
// }
// },
picture: {
type: String,
default: "https://www.dialadocdirect.org/app/storage/images/noimage.jpg",
},
location: String,
type: String,
verified: {
type: Boolean,
default: false,
},
},
{
timestamps: true,
}
);
module.exports = mongoose.model("allied", alliedSchema);
【问题讨论】:
标签: node.js mongoose mongoose-schema