正在尝试读取 mongoDB 个文档属性
Attempting to read mongoDB document properties
我正在尝试从存储在我的 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 时它也是未定义的。
尝试findOne
await serverdata.findOne(...)
使用find
或findMany
将return一个cursor
。
我正在尝试从存储在我的 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 时它也是未定义的。
尝试findOne
await serverdata.findOne(...)
使用find
或findMany
将return一个cursor
。