-2

I'm getting this error which I never used to get before. I haven't changed any code, and I am suddenly getting this weird error and it won't do anything but spit out this error (it won't do the code I want it to do with the database info that I tell it to retrieve).

Error:

(node:11428) UnhandledPromiseRejectionWarning: MongoNetworkError: connection 5 to formbot-shard-00-02-rq3ga.azure.mongodb.net:27017 closed
    at TLSSocket.<anonymous> (C:\Users\seanh\Desktop\Important\AstroServices\FormBot\node_modules\mongodb\node_modules\mongodb-core\lib\connection\connection.js:276:9)
    at Object.onceWrapper (events.js:272:13)
    at TLSSocket.emit (events.js:185:15)
    at _handle.close (net.js:538:12)
    at TCP.done [as _onclose] (_tls_wrap.js:379:7)
(node:11428) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

Code:

exports.run = (bot, message, args) => {
    if(!message.member.roles.has(`${message.guild.roles.find(role => role.name === bot.config.permRole).id}`))
        return message.channel.send(`Sorry, you do not have permission to run that command!`);
    const Discord = require('discord.js');
    const mongoose = require('mongoose');
    const fs = require('fs');

    mongoose.connect(`${bot.config.dbconnection}`, {
        useNewUrlParser: true
    });
    const messages = require('../models/messages.js');
    messages.find({
        serverID: message.guild.id
    }).sort([
        ['message', 'descending']
    ]).exec((err, res) => {
        if(err) console.log(err);

        let embed = new Discord.RichEmbed()
        .setTitle(`Message List`)
        .setColor(bot.config.embedColour)
        .setTimestamp()
        .setThumbnail(message.author.avatarURL)
        .setFooter(`Message list as of`)

        if(res.length === 0) {
            embed.addField(`Messages`, `No messages found`)
        } else if (res.length < 10) {
            for (i = 0; i < res.length; i++) {
                embed.addField(`${i + 1}. ${res[i].name}`, `**Message**: ${res[i].message}\n**Day**: ${res[i].day}`);
            }
        } else {
            for (i = 0; i < bot.config.dbMaxReadLength; i++) {
                embed.addField(`${i + 1}. ${res[i].name}`, `**Message**: ${res[i].message}\n**Day**: ${res[i].day}`);
            }
        }

        message.channel.send(embed);
    });
};

Any help is appreciated as no one is responding on Slack or IRC and I really need the solution to this.

Thank you, Sean.

1
  • Make sure you ask an actual question or questions. Doing this helps you frame the problem more precisely.
    – Paul Gear
    Commented Mar 14, 2019 at 3:40

1 Answer 1

-1

Turns out I needed to allow the IP I was connecting from in my MongoDB IP whitelist.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .