Я создаю api диалогового потока и использую MongoDb для извлечения данных.
Я получаю сообщение об ошибке, когда MOngoDB пытается подключиться к серверу.
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
//const {Card, Suggestion} = require('dialogflow-fulfillment');
const mongoose = require('mongoose');
// you can use your mongodb connection url string
let uri = 'mongodb+srv://adynoruser:Adynor@123@cluster0-i0lae.gcp.mongodb.net/test?retryWrites=true';
let Song;
mongoose.connect(uri,{ useNewUrlParser: true });
let mdb = mongoose.connection;
mdb.on('error', console.error.bind(console, 'connection error:'));
mdb.once('open', function callback() {
// Create song schema
let songSchema = mongoose.Schema({
decade: String,
artist: String,
song: String,
weeksAtOne: Number
});
// Store song documents in a collection called "songs"
// this is important ie defining the model based on above schema
Song = mongoose.model('songs', songSchema);
// Create seed data
let seventies = new Song({
decade: '1970s',
artist: 'Debby Boone',
song: 'You Light Up My Life',
weeksAtOne: 10
});
//use the code below to save the above document in the database!
seventies.save(function (err) {
console.log('saved');
});
});
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
function welcome(agent) {
// I use the code below to find a song from database and ask the user whether he wants to listen to it
// Use the code below to extract data based on your criteria
return Song.find({ 'song': 'You Light Up My Life' }, 'song')
.then((songs) => {
//songs is araay matching criteria, see log output
console.log(songs[0].song);
agent.add(`Welcome to my agent! Would you like to listen ${songs[0].song}?`);
})
.catch((err) => {
agent.add(`Therz some problem`);
});
}
function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
// intentMap.set('your intent name here', yourFunctionHandler);
// intentMap.set('your intent name here', googleAssistantHandler);
agent.handleRequest(intentMap);
});
Я получаю ошибку
ошибка подключения: {Ошибка: querySrv ESERVFAIL _mongodb._tcp.cluster0-i0lae.gcp.mongodb.net
в errnoException (dns.js: 28: 10)
в QueryReqWrap.onresolve [как oncomplete] (dns.js: 219: 19)
код: 'ESERVFAIL',
errno: 'ESERVFAIL',
системный вызов: 'querySrv',
имя хоста: '_mongodb._tcp.cluster0-i0lae.gcp.mongodb.net'}
Я совершенно новичок в Mongodb. Любая помощь приветствуется.