I am not able to encrypt my password during an update using bcrypt on mongoose. The password is changed without problems, but without encryption.
Follow the schema:
var mongoose= require('mongoose');
module.exports= function(){
var schema= mongoose.Schema({
email:{
type: String,
required: true
},
senha:{
type: String,
required: true,
bcrypt: true
},
});
schema.plugin(require('mongoose-bcrypt'));
return mongoose.model('Usuario', schema);}
The following is an excerpt from the controller:
controller.updateUsuario= function(req, res){
var Usuario= app.models.usuario;
var _id= req.params.id;
// Atualização de cadastro
if(_id){
Usuario.findByIdAndUpdate(_id, req.body).exec()
.then(
function(usuario){
res.json(usuario);
},
function(erro){
console.error(erro);
res.status(500).json(erro);
}
);
}};