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

142
Views
Tener problemas con las promesas de mongodb

Así que estoy tratando de ejecutar múltiples consultas, todo mientras creo filas en una hoja de Excel, y luego, después de todo eso, realmente escribo en un archivo de Excel. El problema con el que sigo tropezando es que termino escribiendo en el archivo de Excel antes de terminar. mis consultas y las filas han sido creadas. Aquí está mi código:

 var writeRows = function(){ // setting up of excel file Child.find(function(err,children){ children.forEach(function(item, index){ User.findOne({_id: item.get_gaurdian()}, function(err, parent){ console.log(item.firstname); sheet.addRow({ firstname: item.firstname, lastname: item.lastname, birthday: item.birthday, address: item.address, parent_name: parent.full_name(), // more fields... }); }); }); }); }

Y luego en mi controlador llamo:

 writeRows().then(function(){ d = new Date().toDateString().split(' ').join('_'); filename = './public/spreadsheets/registration_1'+d+'.xlsx'; workbook.xlsx.writeFile(filename) .then(function() { console.log("wrote to a file"); res.send('finished'); }); });

¿Cómo puedo esperar a que se realicen las consultas y se agreguen las filas antes de escribir en el archivo?

over 4 years ago · Santiago Trujillo
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!