Wednesday, 10 May 2017

Mongoose update doesn't work

I'm trying to update a value in mongoose. I tried many different ways but nothing updated the value. This is what i have right now:

    upvote: (req, res) => {
    let id = req.params.id;

    Problem.findById(id).then(problem => {
        console.log(problem.points);
        Problem.update({ _id: req.params.id }, {
            $inc:
            {
                problems: 1,
            }
        }, (e, p) => { console.log(e, p) });
    });
}

I'm getting null { ok: 0, n: 0, nModified: 0 } printed out and before that i have the right value for points so i know it finds the right document. But it doesn't ever update it.



via Kys Plox

No comments:

Post a Comment