Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript MongoDb更新状态_Javascript_Mongodb - Fatal编程技术网

Javascript MongoDb更新状态

Javascript MongoDb更新状态,javascript,mongodb,Javascript,Mongodb,我目前正在尝试更新mongoDb中的一个文档。我是mongo的新手,阅读文档对我没有任何帮助+我没有收到任何错误 我的代码 const Guild = require('../schemas/GuildSchema') module.exports = { name: 'whitelist', description: "whitelist", async execute(bot, message, args, PREFIX, Discord, se

我目前正在尝试更新mongoDb中的一个文档。我是mongo的新手,阅读文档对我没有任何帮助+我没有收到任何错误

我的代码

const Guild = require('../schemas/GuildSchema')

module.exports = {
    name: 'whitelist',
    description: "whitelist",
    async execute(bot, message, args, PREFIX, Discord, settings, fs) {

        if (message.author.id != "173347297181040640") {
            return message.channel.send("Sorry only Bacio001 can whitelist!")
        }

        if (!args[1]) {
            return message.channel.send("No guild id given!")
        }

        try {

            Guild.findOneAndUpdate(
                { guildid: args[1]},
                { $set: { whitelisted : true } }
            )

        } catch (e) {

            console.log(e);

        }

        let guild = bot.guilds.cache.get(args[1]);

        message.channel.send(`Whitelisted ${guild.id} with the name ${guild.name} !`)
        
    }
}

所以我最终找到了我不得不等待公会的问题。findOneAndUpdate

const Guild = require('../schemas/GuildSchema')

module.exports = {
    name: 'whitelist',
    description: "whitelist",
    async execute(bot, message, args, PREFIX, Discord, settings, fs) {

        if (message.author.id != "173347297181040640") {
            return message.channel.send("Sorry only Bacio001 can whitelist!")
        }

        if (!args[1]) {
            return message.channel.send("No guild id given!")
        }

        try {

            await Guild.findOneAndUpdate(
                { guildid: args[1]},
                { whitelisted : true }
            )

        } catch (e) {

            console.log(e);

        }

        let guild = bot.guilds.cache.get(args[1]);

        message.channel.send(`Whitelisted ${guild.id} with the name ${guild.name} !`)
        
    }
}