【发布时间】: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