Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

140
Vistas
Why does the agent.add() function display an empty string
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) });

This is a code i have for finding data inside a mongodb schema and i would like to use the value from resultArray to add it into the dialogflow chatbot. Inside the promise, the global variable string changes value but after the query, it seems to be empty. When i use the agent.add() function (for displaying text in the chatbot) it does not update the string at all even if the console.log() displays the value in 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"));
  }

Above is the full function used by Dialogflow

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

Here is the code to search the db

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda