schema.pre()フックがそれを行うだろう。例:彼らは独断回答やスパムを誘致する傾向があるよう
export const schema = new mongoose.Schema({
name: String,
username: {
type: String,
required: true,
unique: true
},
password: {
type: String,
required: true
}
}, { timestamps: { createdAt: "created_at", updatedAt: "updated_at" }
});
schema.pre("save", function (next) {
bcrypt.hash(this.password, 10, (err, hash) => {
this.password = hash;
next();
});
});
schema.pre("update", function (next) {
bcrypt.hash(this.password, 10, (err, hash) => {
this.password = hash;
next();
});
});
質問**オフトピックスタックオーバーフローのためにある書籍、ツール、ソフトウェアライブラリ、チュートリアルや他のオフサイトのリソースをお勧めしますか見つけるために私たちを求めて。代わりに、[問題を説明する](http://meta.stackoverflow.com/questions/254393)、これを解決するためにこれまでに何が行われているか。 –