我想在express.js控制器中获取一个变量到 模式,以便对变量和结果执行某些操作 模式内部的操作。下面的例子
express.js
userschema.full_name = fullName;
userschema.other_fields = other_details;
var variableName = 'inside the controller';
schema2 = new schema(req.body);
schema1.save(function (err, result){
});
schema1.js
var schema1 = mongoose.Schema({
full_name: String,
other_fields : String//etc
})
schema1.pre('save', function(){
var fullName = this.full_name;
var otherFields = this.other_fields;
//get variableName which is inside the controller
//but is not a field in schema1
//perform operation inside schema and compare
//result with controller variableName
})
如何获取变量名,该变量名在控制器内部但不是 schema1中的字段在模式内部执行操作并比较结果 与控制器variableName