Using setter in Mongoose

According to mongoose.js doc, it is able to set setters to a field on schema.
However, the doc is not quite detailed and obselete.
Some example:

1
2
3
4
5
6
7
8
9
10
11
var schema=new Schema({
password:{
type:String,
required:true,
set:hash
}
})

function hash(plainPwd){
return require("crypto").createHash("sha1").update(plainPwd).update(secret).digest("hex");
}