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

270
Views
this.array.length no funciona como valor predeterminado para una propiedad en Mongoose Schema

Tengo el siguiente esquema de mangosta

 const groupSchema = new mongoose.Schema({ club:{ type: mongoose.Schema.Types.ObjectId, ref: 'Club', required:true, }, group:[{ team:{ type: mongoose.Schema.Types.ObjectId, ref: 'Team', required:true, }, wins:[{ type: mongoose.Schema.Types.ObjectId, ref: 'Game', default:[], }], points:{ type: Number, default: function(){ return this.wins.length } }, }], },{timestamps:true})

El problema que tengo es con el valor predeterminado del atributo de points . Debería return this.wins.lenght , pero permite devolver 0 .

Cuando lo probé con this._id , confirmó que me refiero al objeto correcto ya que era igual a la identificación del subdocumento, pero no funciona con this.wins.length

¿alguna sugerencia?

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!