Mongodb 如果架构中未列出字段,如何使Mongoose不保存字段

Mongodb 如果架构中未列出字段,如何使Mongoose不保存字段,mongodb,mongoose,schema,Mongodb,Mongoose,Schema,例如,如果我发送一个保存新用户的post请求,并添加一个附加字段“Name”:“oscar”,如果该字段未在架构中列出,则该字段将保存到mongodb事件。如果架构中没有列出,我需要阻止保存 const User = new Schema( { userName: { type: String, required: schemaErrorRequired('login'), unique: schemaErrorUnique('login'),

例如,如果我发送一个保存新用户的post请求,并添加一个附加字段
“Name”:“oscar”
,如果该字段未在架构中列出,则该字段将保存到mongodb事件。如果架构中没有列出,我需要阻止保存

const User = new Schema(
  {
    userName: {
      type: String,
      required: schemaErrorRequired('login'),
      unique: schemaErrorUnique('login'),
    },
    email: {
      type: String,
      required: schemaErrorRequired('email'),
      unique: schemaErrorUnique('email'),
    },
    pass: {
      type: String,
      required: 'Save error',
    }
);

显然,猫鼬5.8并没有出现这种情况