我有一个虚拟混合类型的mongoose模式。例如:
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 {}”,为什么这不起作用?