-
In Mongoose, we can add methods to documents as follows: const userSchema = new mongoose.Schema({
balance: Number
})
userSchema.methods.withdrawBalance = function(amount){
const doc = this
doc.balance = doc.balance - amount
} and we can use it as follows: const userDoc = UserModel.findById(ID_HERE);
userDoc.deductBalance(100); // -100$ USD
userDoc.save() I want to be able to do the same on the models the same way I can do it on documents, I want to be able to do something like that: const userDoc = UserModel.findById(ID_HERE).myCustomMethod() But How? |
Beta Was this translation helpful? Give feedback.
Answered by
vkarpov15
Sep 12, 2022
Replies: 1 comment
-
Query helpers. See: |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
samislam
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Query helpers. See: