Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DeprecationWarning: Collection#find: pass a function instead

I'm quite a newbie to node.js and I'm currently using discord.js to make a Discord bot. As soon as any bot command gets used the console prints a DeprecationWarning. for example:

(node:15656) DeprecationWarning: Collection#find: pass a function instead

(node:15656) sometimes is another number, nearly always changing.
This is what my code looks like (only one command, I've got multiple, I get this error with all of them though):

const botconfig = require("./botconfig.json")
const Discord = require("discord.js");
const bot = new Discord.Client();

bot.on("ready", () => { 
    console.log(`Launched ${bot.user.username}...`);
    bot.user.setActivity("Games", { type: "PLAYING" });
});

bot.on("message", async message => {
    if (message.author.bot) return;

    let prefix = botconfig.prefix;
    let messageArray = message.content.split(" ");
    let cmd = messageArray[0];
    let args = messageArray.slice(1);
    let botico = bot.user.displayAvatarURL;

    if (cmd == `${prefix}help`) {
        let helpEmbed = new Discord.RichEmbed()
            .addField(".kick", "kick a user", true)
            .addField(".ban", "ban a user", true)
            .addField(".unban", "unbans a user", true)
            .addField(".mute", "mutes a user over a period of time", true)
            .setColor("#005b5f")
            .setThumbnail(botico);

        message.channel.send(helpEmbed);
        console.log(`command used: help`);
    };
});

bot.login(botconfig.token)
like image 560
pnda Avatar asked Aug 26 '18 12:08

pnda


People also ask

What can I use instead of useCreateIndex?

useNewUrlParser , useUnifiedTopology , useFindAndModify , and useCreateIndex are no longer supported options. Mongoose 6 always behaves as if useNewUrlParser , useUnifiedTopology , and useCreateIndex are true , and useFindAndModify is false . The solution is to remove any unsupported options from your code.

Is findOneAndUpdate deprecated?

findOneAndUpdate() , by default you'll see one of the below deprecation warnings. DeprecationWarning: Mongoose: `findOneAndUpdate()` and `findOneAndDelete()` without the `useFindAndModify` option set to false are deprecated.

Is useNewUrlParser deprecated?

Is useNewUrlParser deprecated? The useNewUrlParser Option DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.

How do you fix a deprecation warning?

To fix all deprecation warnings, follow the below steps: Replace update() with updateOne() , updateMany() , or replaceOne() Replace remove() with deleteOne() or deleteMany() . Replace count() with countDocuments() , unless you want to count how many documents are in the whole collection (no filter).


1 Answers

It is in one of your other commands. You more than likely are using something like #Collection.find('name', 'keyname') in one of the other commands.

This has been updated to #Collection.find(x => x.name === "name").

Like it says in the error. #Collection.find() requires a function instead. So use one and the error goes away.

like image 194
Nedinator Avatar answered Oct 23 '22 10:10

Nedinator