📜  mongoose setter 和 getter - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:47.478000             🧑  作者: Mango

代码示例1
function toLower (v) {
  return v.toLowerCase();
}

var UserSchema = new Schema({
  email: { type: String, set: toLower } 
});

var User = mongoose.model('User', UserSchema);
var user = new User({email: 'AVENUE@Q.COM'});

console.log(user.email); // 'avenue@q.com'