weixin_39928787
weixin_39928787
2020-12-01 13:13

Validation error while creating generated user model


var userSchema = new mongoose.Schema({
    name: {
        first: {type: String, required: true, trim: true},
        last: {type: String, required: true, trim: true}
    },
    password: {type: String, select: false}
});

nev.generateTempUserModel(User)

var user = new User();
user.name.first = req.body.name.first;
user.name.last = req.body.name.last;

nev.createTempUser is throwing below validation error


ValidationError: temporary_users validation failed for name.first and name.last

Please let me know if this expected or error from my side

该提问来源于开源项目:whitef0x0/node-email-verification

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

5条回答

  • weixin_39613188 weixin_39613188 5月前

    Same is with me. temporary_users validation failed. I thought the schema was not getting generated. But it is getting generated, still throwing this error? Why?

    点赞 评论 复制链接分享
  • weixin_39965283 weixin_39965283 5月前

    hey, sorry I haven't worked on this in a while. I will try to get around to it sometime this week!

    点赞 评论 复制链接分享
  • weixin_39835991 weixin_39835991 5月前

    LET'S HACK IT BRUH

    On Wed, Mar 2, 2016 at 1:26 PM Dakota St. Laurent notifications.com wrote:

    hey, sorry I haven't worked on this in a while. I will try to get around to it sometime this week!

    — Reply to this email directly or view it on GitHub https://github.com/SaintDako/node-email-verification/issues/31#issuecomment-191360000 .

    点赞 评论 复制链接分享
  • weixin_39613188 weixin_39613188 5月前

    Hey, guys, it's solved now. If your main schema has some components which in which required is true and while creating a new temporary object you don't declare them, you get an error saying temporary_users validation failed.

    点赞 评论 复制链接分享
  • weixin_39630762 weixin_39630762 5月前

    but if you set persistent user model , then it automatically takes care of it, right?

    点赞 评论 复制链接分享

相关推荐