1
我想要在Schema.ObjectId上定义一个新方法,这样当我在一个Schema.ObjectId的实例上调用它时,它应该调用它。在Schema.ObjectId上定义一个方法
Schema.ObjectId.truncate = function(){
return this.toString(0,4) + this.toString(this.length-4);
}
User.findById(id, function(err, user){
console.log(user.id.truncate());
});
上面的东西(它不起作用)。
我甚至在Schema.ObjectId.prototype
上试过,但它说它没有定义。