Mongoose create a new object within a static function Mongoose create a new object within a static function mongoose mongoose

Mongoose create a new object within a static function


When you first call the static function this is bound to the model for the schema. You can just do something like this:

someSchema.static('foo', function() {    const newUser = new this({        username: username,         password: password,    });    newUser.save(cb);})

Don't replace the anonymous function with a fat arrow equivalent (I know you want to!). this won't have the correct scope.