U
U
UNy2018-05-28 01:58:33
MongoDB
UNy, 2018-05-28 01:58:33

Why doesn't it update the collection document field?

I have a users collection created with mongoose. I'm trying to update the password field of this collection in the document:

exports.ChangePassword = function (user,userPasswords) {
    User
        .findOne({name:user})
        .then(function (doc) {
            if (hash(userPasswords.old = doc.password)){
                User.update({name:doc.name},{$set:{password:userPasswords.new}})
            }
        })
};

function hash(text) {
    return crypto.createHash('sha1')
        .update(text).digest('base64')
}

Enters the if block to password does not change. What is the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly F., 2018-05-30
@FuN_ViT

It seems to me that you have an error in the if. Even two...
And it seems like it's lost in $set hash...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question