Home > OS >  Attempting to read mongoDB document properties
Attempting to read mongoDB document properties

Time:04-19

I'm trying to read the property levelenabled from a document stored in my MongoDB database. When I log the returned data to console after finding the document with the GuildID(discord.js) it logs the correct document but when I try to check a value in that data the property I'm checking is undefined. Here is my code:

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

And yes the function is async

I should also add that yes the property levelenabled exists in the document and when logging the GuildID it also is undefined.

CodePudding user response:

Try findOne

await serverdata.findOne(...)

Using find or findMany will return a cursor.

  • Related