Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error when trying to push something in mongodb

code

      case 'setup':
        let serverSetup = ServerDoc.findOne({id: message.guild.id})
        if(serverSetup) return console.log(serverSetup)
        if(!serverSetup){
          let newServersetup = new ServerDoc({name: message.guild.name})
           newServersetup.save();
             console.log(newServersetup)
        }   

error
https://pastecord.com/zutetugymo
because I couldn’t paste here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

What you think is your error is actually the result of the ServerDoc.findOne(). Since you are not using await or .then() when you are finding a document from your collection, this is what you get when you use .findOne(). To actually get the data instead of this, you just have to change your code to this:

case 'setup':
    let serverSetup = await ServerDoc.findOne({id: message.guild.id})
    if(serverSetup) return console.log(serverSetup)
    if(!serverSetup){
        let newServersetup = new ServerDoc({name: message.guild.name})
        newServersetup.save();
        console.log(newServersetup)
    } 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading