Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
Mongoose no puede registrarse como usuario

Obtuve un ValidatorError al intentar agregar un nuevo usuario usando mi API... Obtuve el siguiente error, aunque se enviaron los campos obligatorios. Realmente no puedo entender por qué. He agregado la parte relevante del código. Gracias.

ingrese la descripción de la imagen aquí

Aquí está mi código: userModel.js

 const mongoose = require('mongoose'); const validator = require('validator'); const userSchema = new mongoose.Schema({ name: { type: String, required: [true, 'Please tell us your name!'], }, mobile: { type: Number, required: [true, 'Please tell us your mobile number!'], unique: true, }, email: { type: String, unique: true, lowercase: true, validate: [validator.isEmail, 'Please provide a valid email'], }, photo: { type: String, default: 'default.jpg', }, role: { type: String, enum: ['user', 'guide', 'lead-guide', 'admin'], default: 'user', }, password: { type: String, required: [true, 'Please provide a password'], minlength: 8, select: false, }, passwordConfirm: { type: String, required: [true, 'Please confirm your password'], validate: { //This only works on create and save validator: function (el) { return el === this.password; }, message: 'Passwords are not the same!', }, }, passwordChangedAt: Date, passwordResetToken: String, passwordResetExpires: Date, active: { type: Boolean, default: true, select: false, }, referralCode: String, address: String, occupation: String, education: String, socialSiteLink: String, maritalStatus: String, religion: String, language: String, employmentStatus: String, }); const User = mongoose.model('User', userSchema); module.exports = User;

authControler.js

 const User = require('../models/userModel'); const catchAsync = require('../utils/catchAsync'); exports.signup = catchAsync(async (req, res, next) => { const newUser = await User.create(req.body); res.status(201).json({ status: 'success', data: { user: newUser, }, }); });

catchAsync.js

 module.exports = (fn) => { return (req, res, next) => { fn(req, res, next).catch(next); }; };
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!