Mongoose: validation error path is required

后端 未结 5 2070
一整个雨季
一整个雨季 2020-12-09 15:55

I\'m trying to save a new document in mongodb with mongoose, but I am getting ValidationError: Path \'email\' is required., Path \'passwordHash\' is required., Path \'

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-09 16:40

    To solve this type of error

    ValidationError: Path 'email' is required.
    

    your email is set required in Schema, But no value is given or email field is not added on model.

    If your email value may be empty set default value in model or set allow("") in validatior. like

     schemas: {
        notificationSender: Joi.object().keys({
            email: Joi.string().max(50).allow('')
        })
      }
    

    I think will solve this kind of problem.

提交回复
热议问题