The method is relatively simple, rough and ugly, which is to access the static method through the constructor, roughly as follows:
1
|
WorkSpaceSchema.methods.getPrice = function(startTime, endTime){
|
After seeing this solution, my first thought was why Mongoose didn’t consider the access between methods when designing it. If you think about it carefully, the original intention of the static method is just to pass the Model already. There are ways to extend and customize it, create some special search methods, etc., and if you want to create methods that are called in other methods, a better solution is to write a separate module and then export and call it.