草庐IT

changedName

全部标签

node.js - 如何在 Mongoose 中添加模式方法?

这个问题在这里已经有了答案:VirtualsvsMethodsinMongoose(2个回答)关闭6年前。我一直在尝试找出如何在Mongoose中添加模式方法,这些方法将使用模型属性并以某种方式修改它们。是否可以使下面的代码工作?varmySchema=newSchema({name:{type:String},createdAt:{type:Date,default:Date.now},changedName:function(){returnthis.name+'TROLOLO';}}); MySchema.findOne({_id:id}).exec(function(error

node.js - 如何在 Mongoose 中添加模式方法?

这个问题在这里已经有了答案:VirtualsvsMethodsinMongoose(2个回答)关闭6年前。我一直在尝试找出如何在Mongoose中添加模式方法,这些方法将使用模型属性并以某种方式修改它们。是否可以使下面的代码工作?varmySchema=newSchema({name:{type:String},createdAt:{type:Date,default:Date.now},changedName:function(){returnthis.name+'TROLOLO';}}); MySchema.findOne({_id:id}).exec(function(error