我正在嘗試從存盤在我的 MongoDB 資料庫中的檔案中讀取屬性 levelenabled。當我在找到具有 GuildID(discord.js) 的檔案后將回傳的資料記錄到控制臺時,它會記錄正確的檔案,但是當我嘗試檢查該資料中的值時,我正在檢查的屬性是未定義的。這是我的代碼:
const data = await serverdata.find({ //note serverdata is a reference to the serverdata Schema
GuildID:message.guild.id
});
if(!data) return;
console.log(data.levelenabled) //the output of this is undefined therefore I can not check the boolean status
是的,功能是異步的
我還應該補充一點,是的,檔案中存在屬性 levelenabled,并且在記錄 GuildID 時它也是未定義的。
uj5u.com熱心網友回復:
嘗試findOne
await serverdata.findOne(...)
使用findorfindMany將回傳一個cursor.
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/459382.html
