Reputation: 127
I'm trying to update my user document to change the password but mongodb ignore the field password when I pass a bcrypt hashed password as $2a$10$lnTLIgnOWuoolOkqBfzcd.0pNLFtstX20p8KJNQmKkL.6D.W7Zu0a
If I remove the first $
that work.
my update func
func (r Repo) Update(id string, updUsr interface{}) (User, error) {
// uid work
filter := bson.M{"_id": bson.M{"$eq": uid}, "deleted_at": nil}
update := []bson.D{
{primitive.E{
Key: "$set",
Value: updUsr,
}},
{primitive.E{
Key: "$addFields",
Value: bson.D{primitive.E{
Key: "modified_at",
Value: time.Now(),
}},
}},
}
res := r.col.FindOneAndUpdate(
r.ctx,
filter,
update,
)
if res.Err() != nil {
// err
}
// decode work
return u, nil
}
my update func call
// doesn't work
updPwd := password{
Password: "$2a$10$lnTLIgnOWuoolOkqBfzcd.0pNLFtstX20p8KJNQmKkL.6D.W7Zu0a",
}
// working version
updPwd := password{
Password: "2a$10$lnTLIgnOWuoolOkqBfzcd.0pNLFtstX20p8KJNQmKkL.6D.W7Zu0a",
}
_, err = us.Update(uid, updPwd)
if err != nil {
// err
}
I don't know how to passe my hash variable to mongodb actually that just remove my password key because I proccess like password is an empty value and if I remove the first $
sign my update is successfully.
Every review is appreciate !
Thank
Upvotes: 1
Views: 319