Привет, я никогда не использовал пн goose, но мы можем практически создать прототип для модели Item. Я предполагаю, что этот код будет работать?
const item = new mongoose.Schema({
payment: {
productTotal: Number,
tax: Number,
},
});
const Item = mongoose.model("Item", item);
Item.prototype.subtotal = function () {
return this.payment.productTotal + this.payment.tax;
};
const newItem = new Item({ payment: { productTotal: 10, tax: 10 } });
// Obv you need to call it as function :)
console.log(newItem.subtotal());
Я проверил документацию из mon goose не удалось найти ничего связанного с геттером