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

138
Views
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
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!