文档,使用更新的字段创建一个新文档,保留原始文档"/>
如果找到,我想更新付款文档,使用更新的字段创建一个新文档,保留原始文档
const payment = await paymentsSchema.findOne({ student: s_id, guardian: g_id }, {},
{ sort: { 'createdAt': -1 } })
console.log(payment)
payment.balance = (payment.balance + settings.overtime_rate)
// Create a new document with the updated values
const updatedPayment = paymentsSchema(payment.toObject());
// Save the new document to the database
updatedPayment.save((err) => {
if (err) throw err;
console.log('Payment updated successfully');
});
我希望在发布此更新后有 2 个文件,原始文件和更新后的文件...
回答如下:const payment = await paymentsSchema.findOne({ student: s_id, guardian: g_id }, {},
{ sort: { 'createdAt': -1 } },)
console.log(payment)
payment.balance = (payment.balance + settings.overtime_rate)
// Create a new document with the updated values
const updatedPayment = new paymentsSchema({
balance: payment.balance,
. . . //other fields you may have
});
// Save the new document to the database
updatedPayment.save((err) => {
if (err) throw err;
console.log('Payment updated successfully');
});
更多推荐
如果找到,我想更新付款文档,使用更新的字段创建一个新文档,保留原始文档
发布评论