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

137
Views
¿Por qué la función agent.add() muestra una cadena vacía?
db.findMarami(Scholarship, {}, {scholarship_type:1, _id:0}).then(resultArray => { let list = resultArray.map(scholarship => scholarship.scholarship_type); final_list.push(list); string = final_list.toString(); //console.log(list.toString()); console.log(string); agent.add(string); }).catch((error) => { console.log(error) });

Este es un código que tengo para encontrar datos dentro de un esquema mongodb y me gustaría usar el valor de resultArray para agregarlo al chatbot de flujo de diálogo. Dentro de la promesa, la cadena de la variable global cambia de valor, pero después de la consulta, parece estar vacía. Cuando uso la función agent.add() (para mostrar texto en el chatbot), no actualiza la cadena en absoluto, incluso si console.log() muestra el valor en cmd. (DIALOGFLOW MONGODB NODEJS)

 function scholarshipTypes(agent){ //static data handling should be shown here agent.add("There are numerous types of scholarships within DLSU. Listed below are the types of scholarships."); //mongodb operations to obtain static data from db db.findMarami(Scholarship, {}, {scholarship_type:1, _id:0}).then(resultArray => { let list = resultArray.map(scholarship => scholarship.scholarship_type); final_list.push(list); string = final_list.toString(); //console.log(list.toString()); console.log(string); agent.add(string); }).catch((error) => { console.log(error) }); agent.add("More scholarship details:"); agent.add(new Suggestion("Deadlines")); agent.add(new Suggestion("Requirements")); agent.add(new Suggestion("Application Forms")); }

Arriba está la función completa utilizada por Dialogflow

 findMarami: function (model, query, projection, callback) { return model.find(query, projection); },

Aquí está el código para buscar en la base de datos.

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!