node.js - 如何从 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);
});
解决方案
推荐阅读
- mysql-8.0 - 错误代码:3685。正则表达式的非法参数
- qt - 不能 qmake QtWebengine - “qtwebenginecore-config.pri:没有这样的文件或目录”
- node.js - WebSocket 握手期间出错:意外的响应代码:https 上的 400
- angular - 如何将逗号分隔值拆分为角度表格
- javascript - 将图例和节点更改为圆形图像
- swift - 有没有办法让小部件捕获 UNUserNotificationCenterDelegate?迅速
- oracle - 如何使用 UTL_FILE 包在地图驱动器上写入文件?
- dart - 等待和完成者之间的飞镖关系
- mongodb - 使用 ObjectId 作为本地和外部字段的集合的 Mongodb 查找查询?
- twilio - Twilio Studio - 消息服务 + 收件箱