내가 이벤트를 저장 몽구스의 사전 처리기를 지정하고 문서를 암호화하려고에 저장 사전을 사용하여 문서를 변경하는 방법 :저장하기 전에 몽구스
userShecma.pre('save', function(next) {
var self = {};
self.Key = this.password;;
self.EncriptedString = encrypt.encrypt(JSON.stringify(this), this.password);
self.user = this.user
self.decrypt = function() {
var user = JSON.parse(encrypt.decrypt(this.EncriptedString, this.Key));
for(var key in user) {
this[key] = user[key];
}
}
for(var key in this){
delete this[key];
}
for(var key in self){
this[key] = self[key];
}
console.log(this);
next(self);
});
내가 diffrent 가지의 무리를 시도, 때때로 오류가 발생하는 경우가 있습니다. 문서를 변경하지 못하는 경우도 있습니다.
당신이 어떤 더 많은 정보가 필요하면 알려줘,
아리
편집 : Benoir의 대답을 시도, 내가 this
을 편집 할 수 없습니다.
this.getValue와 this.setValue를 사용하여 스키마에서 정의하지 않은 속성을 편집 할 수있다. –