Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

45
Views
I can't edit the object on mongo database

So i am trying to check if the user has the object with id: 1 after that i try to edit values of this object but it doesn't edit it!

I tried to console.log(quest) and it logged the quest object

       let data;
        try{
            data = await schema.findOne({
                userID: message.author.id
            })
            if(!data) {
            data = await schema.create({
                userID: message.author.id
            })
            }
        } catch(err) {
            console.log(err)
        }

        const quest = data.progress.quests.find(x => x.id == 1)
        quest.current++
        await data.save()

This is how quests array looks in the database

[
    {
        "name": "Say Hi in chat",
        "progress": 5,
        "current": 0,
        "id": 1,
        "reward": 500
    },
    {
        "name": "Play video games",
        "progress": 10,
        "current": 0,
        "id": 2,
        "reward": 250
    },
    {
        "name": "Walk for a time",
        "progress": 5,
        "current": 0,
        "id": 3,
        "reward": 250
    }
]
7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs