Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想给 Schema 类添加一个静态方法,不改变主 Schema 类怎么办?
谢谢
这是网站记录它的方式:
// assign a function to the "statics" object of our animalSchema animalSchema.statics.findByName = function (name, cb) { this.find({ name: new RegExp(name, 'i') }, cb); }