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
mangosta agregar un campo a un documento desde otro documento

Quiero obtener categorías por límite, compensación, orden por espectadores de VideoSchema

 const CategoriesSchema = new Schema<ICategories>({ name: String, image: String, }); const VideoSchema = new Schema<IVideo>({ videoSource: String, // from CategoriesSchema schema category: { name: String, image: String, }, viewers: Number, });

Lo que hago para conseguir lo que quiero:

 const resolver = async ({ args: { limit, offset } }) => { // there are 60k+ categories so request will be long const categories = await CategoriesModel.find(); for (let i = 0; i < categories.length; i++) { const streams = await VideosModel.find({ 'category.name': categories[i].name }); categories[i] = { ...categories[i], // count viewers of current video viewers: streams.reduce((acc, curr) => acc + curr.viewers, 0), }; } // sort by viewers, slice array by limit and offset return categories.sort(({ viewers: viewersA = 0 }, { viewers: viewersB = 0 }) => viewersB - viewersA).slice(offset, limit); },

Entiendo que la solicitud no está optimizada, pero no puedo averiguar cómo hacer la solicitud por límite y compensación y ordenarla según el recuento actual de espectadores. Sé que en una base de datos relacional como mysql puedo usar la combinación izquierda para ese caso, pero no entiendo cómo hacer algo así con mangosta

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!