I was trying to create a new function for a Model not a instance. In other words, a User.func() not a user.func().
I read its doc and found statics keyword for model, and method keyword for instance. Here is what I was trying.
Transaction.statics.createTransactions = async (userOId, type, netChange) => {
const oldBalance = await User.findOne({ _id: userOId }).points;
return this.create({ userOId, type, balance: { netChange, newBalance: oldBalance + netChange } });
};
However, it reports this.create is not a function.