Say I have a mongoose model m
.
This model m
was created using a scheme s
that adds a method to register things:
s.methods.log = function(s) {
this.theLogger(s);
}
theLogger should be served at any time, so I feed theLogger as fast as possible.
It works:
const x = await m.findOne({_id: ...});
x.log("something");
The problem is that this will not work:
const x = new m();
x.log("something");
Is it possible to catch the moment x
with the help of the operator new
?
source
share