我有一个混合类型的虚拟猫鼬模式。例如:
var mongoose = require('mongoose') // version 3.3.1
var FooSchema = new mongoose.Schema( { x: Number } );
FooSchema.virtual('v').set( function(value){
console.log("SETTING", value);
});
var Foo = mongoose.model('Foo', FooSchema);
new Foo( { v:1 } );
new Foo( { v:[] } );
new Foo( { v:{} } );
当我运行此代码时,我得到:
SETTING 1
SETTING []
您会注意到它从不显示“SETTING {}”,为什么这不起作用?