Accesing a MongoDb Cluster Connection Error












0















I am creating a dialogflow api and using MongoDb to retrive data.
I am getting an error while MOngoDB is trying to connect to the server.



 '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);
});


The error I am getting is




connection error: { Error: querySrv ESERVFAIL _mongodb._tcp.cluster0-i0lae.gcp.mongodb.net
at errnoException (dns.js:28:10)
at QueryReqWrap.onresolve [as oncomplete] (dns.js:219:19)
code: 'ESERVFAIL',
errno: 'ESERVFAIL',
syscall: 'querySrv',
hostname: '_mongodb._tcp.cluster0-i0lae.gcp.mongodb.net' }




I am completely new to Mongodb. Any help is appreciated.










share|improve this question



























    0















    I am creating a dialogflow api and using MongoDb to retrive data.
    I am getting an error while MOngoDB is trying to connect to the server.



     '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);
    });


    The error I am getting is




    connection error: { Error: querySrv ESERVFAIL _mongodb._tcp.cluster0-i0lae.gcp.mongodb.net
    at errnoException (dns.js:28:10)
    at QueryReqWrap.onresolve [as oncomplete] (dns.js:219:19)
    code: 'ESERVFAIL',
    errno: 'ESERVFAIL',
    syscall: 'querySrv',
    hostname: '_mongodb._tcp.cluster0-i0lae.gcp.mongodb.net' }




    I am completely new to Mongodb. Any help is appreciated.










    share|improve this question

























      0












      0








      0








      I am creating a dialogflow api and using MongoDb to retrive data.
      I am getting an error while MOngoDB is trying to connect to the server.



       '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);
      });


      The error I am getting is




      connection error: { Error: querySrv ESERVFAIL _mongodb._tcp.cluster0-i0lae.gcp.mongodb.net
      at errnoException (dns.js:28:10)
      at QueryReqWrap.onresolve [as oncomplete] (dns.js:219:19)
      code: 'ESERVFAIL',
      errno: 'ESERVFAIL',
      syscall: 'querySrv',
      hostname: '_mongodb._tcp.cluster0-i0lae.gcp.mongodb.net' }




      I am completely new to Mongodb. Any help is appreciated.










      share|improve this question














      I am creating a dialogflow api and using MongoDb to retrive data.
      I am getting an error while MOngoDB is trying to connect to the server.



       '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);
      });


      The error I am getting is




      connection error: { Error: querySrv ESERVFAIL _mongodb._tcp.cluster0-i0lae.gcp.mongodb.net
      at errnoException (dns.js:28:10)
      at QueryReqWrap.onresolve [as oncomplete] (dns.js:219:19)
      code: 'ESERVFAIL',
      errno: 'ESERVFAIL',
      syscall: 'querySrv',
      hostname: '_mongodb._tcp.cluster0-i0lae.gcp.mongodb.net' }




      I am completely new to Mongodb. Any help is appreciated.







      mongodb dialogflow






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 3 at 13:35









      KhushKhush

      42711541




      42711541
























          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54023365%2faccesing-a-mongodb-cluster-connection-error%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54023365%2faccesing-a-mongodb-cluster-connection-error%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas