首页 > 解决方案 > 如何从 mongoDB 检索数据并使用内联编辑器在对话框流中显示它

问题描述

我正在尝试从 mongoDB atlas 获取保存的数据并将其显示在 dialogflow 聊天机器人中,但它一直告诉我 webhook 截止日期超过了这是我获取数据的代码,如果有人知道如何解决它,请告诉我:

function mongoHandler(agent){
        var MongoClient = require('mongodb').MongoClient;
var url = "mongodb+srv://"my mongoDB atlas credentials"@cluster0.yhuli.mongodb.net";

MongoClient.connect(url,{useUnifiedTopology: true},function(err, db) {
  if (err) throw err;
  var dbo = db.db("FitbitDB");
  var query = { UniqueId: "9657CQ"};
  dbo.collection("fitbit").find(query).toArray(function(err, result) {
    if (err) throw err;
    var x =result[0].FirstName;
    console.log(x);
    agent.add("Hello"+x);
    db.close();
  });
});
    agent.add(`Mongo connected`);// this single line code works but when i try to define x here     it's not working
}

    
      let intentMap = new Map();
    
      intentMap.set('getMongo', mongoHandler);
      agent.handleRequest(intentMap);
    });

标签: node.jsmongodbdialogflow-esmongodb-atlasdialogflow-es-fulfillment

解决方案


推荐阅读