简体   繁体   English

MongooseDB 错误:操作 `levels.findOne()` 缓冲在 10000 毫秒后超时

[英]MongooseDB Error: Operation `levels.findOne()` buffering timed out after 10000ms

I am trying to make a leveling system for my bot (discord.js) and I am using mongoose for the database.我正在尝试为我的机器人 (discord.js) 制作一个调平系统,我正在为数据库使用 mongoose。 Whenever I run the command the bot crashes and this is the error I get:每当我运行命令时,机器人就会崩溃,这是我得到的错误:

C:\Users\Liam\Desktop\slashcmds\node_modules\mongoose\lib\drivers\node-mongodb-native\collection.js:158
          const err = new MongooseError(message);
                      ^

MongooseError: Operation `levels.findOne()` buffering timed out after 10000ms
    at Timeout.<anonymous> (C:\Users\Liam\Desktop\slashcmds\node_modules\mongoose\lib\drivers\node-mongodb-native\collection.js:158:23)
    at listOnTimeout (node:internal/timers:564:17)
    at process.processTimers (node:internal/timers:507:7)

Here is my code:这是我的代码:

const { SlashCommandBuilder } = require('@discordjs/builders');
const { EmbedBuilded, AttachmentBuilder, Embed, EmbedBuilder } = require(`discord.js`);
const { Canvacord } = require('canvacord');
const levelSchema = require(`../../Schemas.js/level`);

module.exports = {
    data: new SlashCommandBuilder()
    .setName('rank')
    .setDescription("Get a server member's XP rank")
    .addUserOption(option => option.setName('target').setDescription("This is the user you want to check the XP rank of.").setRequired(false)),
    async execute(interaction) {
        const { options, user, guild } = interaction;
        const Member = options.getUser('target');
        const member = guild.members.cache.get(Member.id);
        const Data = await levelSchema.findOne({ Guild: guild.id, User: member.id });

        const embed = new EmbedBuilder()
        .setColor('Blue')
        .setTitle(`${member.user.username}'s XP Rank`)
        .setDescription(`${member.user.username} has not gained any XP yet.`)

        if(!Data) return await interaction.reply({ embeds: [embed] });
        await interaction.deferRepy();

        const Required = Data.Level * Data.Level * 20 + 20;
        const rank = new Canvacord.rank()
        .setAvatar(member.displayAvatarURL({ forseStatic: true}))
        .setBackground("IMAGE", `https://cdn.discordapp.com/attachments/1055548593186025513/1057353099720798308/OIP.jpg`)
        .setCurrentXP(Data.XP)
        .setRequiredXP(Required)
        .setRank(1, "Rank", false)
        .setLevel(Data.Level, "Level")
        .setUsername(member.user.username)
        .setDiscriminator(member.user.discriminator)

        const Card = await rank.build();
        const attachment = new AttachmentBuilder(Card, { name: "rank.png" });

        const embed2 = new EmbedBuilder()
        .setColor("Blue")
        .setTitle(`${member.user.username}'s XP Rank`)
        .setImage("attachment://rank.png")

        await interaction.editReply({ embeds: [embed2], files: [attachment] });
    }
}

The bot would crash and send the message "Application did not respond".机器人会崩溃并发送消息“应用程序没有响应”。

Anyone knows how to fix this?任何人都知道如何解决这个问题? I've looked online and nothing shows up for this error.我在网上查看过,但没有显示此错误。

You're calling the model before the connection is established.在建立连接之前,您正在呼叫 model。

According to documentation根据文档

Mongoose lets you start using your models immediately, without waiting for mongoose to establish a connection to MongoDB. Mongoose 让您可以立即开始使用您的模型,而无需等待 mongoose 与 MongoDB 建立连接。

Use mongoose.connect(uri) with async await to establish connection with database and run the command again.使用mongoose.connect(uri)和 async await 建立与数据库的连接并再次运行命令。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MongooseError:操作 `users.findOne()` 缓冲在 10000 毫秒后超时 - MongooseError: Operation `users.findOne()` buffering timed out after 10000ms 操作 `users.findOne()` 缓冲在 10000 毫秒后超时 | 然而数据被接收 - Operation `users.findOne()` buffering timed out after 10000ms | However data is received MongooseError - 操作 `users.findOne()` 缓冲在 10000 毫秒后超时 - MongooseError - Operation `users.findOne()` buffering timed out after 10000ms 无法获得响应,显示操作 users.findOne() 缓冲在 10000 毫秒后超时 - Not able to get response , showing Operation `users.findOne()` buffering timed out after 10000ms` 部署问题 heroku - MongooseError:操作 `users.findOne()` 缓冲在 10000 毫秒后超时 - Issue in deployment heroku - MongooseError: Operation `users.findOne()` buffering timed out after 10000ms MongooseError:操作 .insertOne() 缓冲在 10000 毫秒后超时 - MongooseError: Operation `.insertOne()` buffering timed out after 10000ms 来自 MongoDB 的错误消息“操作 `disneys.insertOne()` 缓冲在 10000 毫秒后超时”” - Error Message from MongoDB "Operation `disneys.insertOne()` buffering timed out after 10000ms"" “错误:MongooseError:操作 `users.insertOne()` 缓冲在 10000 毫秒后超时”, - "Error: MongooseError: Operation `users.insertOne()` buffering timed out after 10000ms", 收到此错误 MongooseError: 在 Heroku 上部署应用程序后 10000 毫秒后操作 `contacts.insertOne()` 缓冲超时 - getting this error MongooseError: Operation `contacts.insertOne()` buffering timed out after 10000ms after deploying the application on Heroku 如何修复 Mongoose 5.11.8 model.find() 错误操作 `thanks-leaderboards.find()` 缓冲在 10000 毫秒后超时 - HOW TO FIX Mongoose 5.11.8 model.find() ERROR Operation `thanks-leaderboards.find()` buffering timed out after 10000ms
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM