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

285
Views
tratando de calcular el promedio con $avg y obtuve: los argumentos deben ser operadores de tubería agregados

obtuve este error: los argumentos deben ser operadores de canalización agregados, este es el curso 'Esquema' que obtuvo bootcamp como objectId.

 const CourseSchema = new mongoose.Schema({ bootcamp: { type: mongoose.Schema.ObjectId, ref: 'Bootcamp', required: true } });

la agregación:

 //static method to get avg of course tuitions CourseSchema.statics.getAverageCost = async function (bootcampId) { console.log('calculating avg cost... with bootcampId:' + bootcampId); const obj = await this.aggragate([{ $match: { bootcamp: bootcampId }, $group: { _id: '$bootcamp', averageCost: { $avg: '$tuition' } } }]); console.log(obj); }

llamando a la agregación antes de guardar o eliminar:

...

 // Call getAvarageCost after save CourseSchema.post('save', function () { this.constructor.getAverageCost(this.bootcamp); }) // Call getAvarageCost before remove CourseSchema.post('remove', function () { this.constructor.getAverageCost(this.bootcamp); })

...

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

$coincidencia y $grupo deben estar en diferentes operaciones de canalización

 const cursor = this.aggregate([ { $match: { bootcamp: bootcampId } }, { $group: { _id: '$bootcamp', averageCost: { $avg: '$tuition' }, }, }, ]) console.log(await cursor.toArray())
about 4 years ago · Juan Pablo Isaza Report
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!