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

128
Views
Mongoose Virtuals: establecedor asíncrono

tengo esta virtual:

 userSchema .virtual('password') .set(function setPassword(password) { this._password = password; this.salt = uuidv1(); this.encry_password = this.securePassword(password); }) .get(function getPassword() { return this._password; });

Ahora mi problema es que this.securePassword(password); es una función asíncrona.

 async securePassword(plainpassword) { if (!plainpassword) return ''; try { return await argon2.hash(plainpassword); } catch (err) { return ''; } }

Ahora si me gusta esto:

 userSchema .virtual('password') .set(function setPassword(password) { this._password = password; this.salt = uuidv1(); this.securePassword(password).then((value) => { this.encry_password = value; }); }) .get(function getPassword() { return this._password; });

O así :

 userSchema .virtual('password') .set(async function setPassword(password) { this._password = password; this.salt = uuidv1(); this.encry_password = await this.securePassword(password) }) .get(function getPassword() { return this._password; });

Lo que me sale es este error:

 "User validation failed: encry_password: Path `encry_password` is required."

¿Alguna solución sobre cómo puedo resolver esta posibilidad con virtuales?

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!