【问题标题】:ERROR: ParallelSaveError: Can't save() the same doc multiple times in parallel错误:ParallelSaveError:无法并行保存()同一个文档
【发布时间】:2021-09-16 01:54:23
【问题描述】:

您好,我遇到了一个错误(我查看了其他人的解决方案,但他们并没有真正帮助我),我不知道它在 discord.js 和 mongodb 中是什么原因造成的 错误如下: UnhandledPromiseRejectionWarning: ParallelSaveError: Can't save() the same doc multiple times in parallel. Document: 60df55dea691a919b4deca21

制作这个的代码在这里:

const serverModel = require('../../models/serverSchema');
module.exports = {
    name: 'hangup',
    description: 'hangup on someone if they like eating cereal with a fork!',
    category: 'fun',
    aliases: global.aliases.fun.hangup,
    cooldown: 5,
    // Umm code i guess
    async execute(message, args, client, serverData) {
        if (serverData.calling == 'connected') {
            console.log('die');
            const OtherPerson = await serverModel.findOne({ talkingWith: serverData.serverID });
            if (OtherPerson) {
                OtherPerson.talkingWith = null;
                OtherPerson.lastMsg = null;
                OtherPerson.calling = 'hangup';
                OtherPerson.save();
            }

        }
        serverData.calling = 'no';
        serverData.channel = '';
        serverData.lastMsg = '';
        serverData.talkingWith = '';
        serverData.save(); //The error brings me here
        message.channel.send(':bangbang:**__Hangingup__ bye bye**:bangbang:');
    },
};

不知道是什么原因

正如我所说,我不知道是什么原因造成的,我正在使用 mongodb 我很确定错误不是来自任何其他脚本

这就是数据库当前的样子 服务器数据:

talkingWith: '860785717882126356';
channel: '856912495737307137';
calling: 'connected';
lastMsg: null;

我不会添加 OtherPerson db 的外观,因为它未知但看起来像“ServerData”

【问题讨论】:

  • 这是因为您正在快速保存它。我认为 mongodb API 有速率限制
  • @MrMythical 是的,这就是问题

标签: mongodb discord.js


【解决方案1】:

我发现了问题

问题是我连续使用这个命令serverData.save();太快了

我通过查看我的事件处理程序找到了它 我通过添加if () 语句来修复它

抱歉这么小的回答,真的没什么好补充的

【讨论】:

    猜你喜欢
    • 2021-03-04
    • 2020-04-11
    • 2021-06-05
    • 2020-04-05
    • 2020-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多