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

149
Views
estoy tratando de crear una ruta que devuelva la suma de todos los valores de un parámetro en una colección

Realmente no sé qué estoy haciendo mal... devuelve una matriz con la cantidad de filas en la colección, pero todas son nulas. seguí la documentación perfectamente pero estoy extremadamente confundido

básicamente tengo una colección en mi base de datos llamada mytest, y estoy tratando de agregar los valores en cada documento (token) para regresar cuando llamo a la ruta /mytest-sum

 module.exports = { /** * Retrieve records. * * @return {Array} */ async Sum(ctx) { let entities; if (ctx.query._q) { entities = await strapi.services.mytest.search(ctx.query); } else { entities = await strapi.services.mytest.find(ctx.query); } //return entities.map(entity => sanitizeEntity(entity, { model: strapi.models.mytest})); entities = entities.map(entity => (entity, { model: strapi.models.mytest })); entities = entities.map(entry => { entry = Object.assign(entry, { sumField: entry.token }); }); return entities; }, };``
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

module.exports = { async Add(ctx) { let add = 0; let fruits = [] // get data from database let entities; if (ctx.query._q) { entities = await strapi.services.mytest.search(ctx.query); } else { entities = await strapi.services.mytest.find(ctx.query); } //get specific data-field from data and map it to an array fruits = entities.map(entity => sanitizeEntity(entity, { model: strapi.models.mytest }).token); // add array values in for loop for (let i = 0; i < fruits.length; i++) { add += fruits[i]; } //return sum as a number return add; }};
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!