我的MongoDB中有两个模型,分别是银行模型和付款模型。银行有美元和zwd两种货币。我想创建一个函数,该函数在付款时会更新银行模型,而只影响付款模型中支付的货币
我希望将银行的值更新为(500-20)
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const bankschema = new Schema({
usd: Number,
zwd: Number
});
const Bank = mongoose.model("Bank", bankschema);
const paymentSchema = new Schema({
paymentAmount: Number,
currency: String,
});
const Payment = mongoose.model("Payment", paymentSchema);
const bankDeposit = new Bank({
usd: 500,
zwd: 1000,
}).save();
const newPayment = new Payment({
paymentAmount : 20,
currency: "usd",
}).save();
function updateBank(){
// the function which will update the Bank value
}