对于db中不太紧急的字段,我应该填写什么?

时间:2019-10-01 10:24:30

标签: mongodb mongoose

我有一个数据库架构,该架构要求注册人员的linkedin url。我不希望他们在注册本身上填写linkedin ID,他们可以自由在仪表板上添加它。下面给出的是该模型的代码

const master = mongoose.model('master', new mongoose.Schema({
  firstName: {type: String, required: true, unique: false},
  lastName: {type: String, required: true, unique: false},
  email:  {type: String, required: true, unique: true },
  linkedinUrl:  {type: String, required: false, unique: false },
  password: {type: String, required: true, unique: false}
},{strict: true}))

当我多次将该字段留空时,数据库返回一个错误

error: "{"driver":true,"name":"MongoError","index":0,"code":11000,"errmsg":"E11000 duplicate key error collection: maindb.mentors index: linkedinUrl_1 dup key: { : \"\" }"}"

我意识到拥有多个null值是一个问题。我还可以使用其他什么值来屏蔽空白字段?谢谢

0 个答案:

没有答案