mongoose有findAndUpdate函数吗?

ygya80vv  于 2022-11-24  发布在  Go
关注(0)|答案(1)|浏览(107)

我知道mongoose的findOneAndUpdate只能过滤一个值。我如何过滤两个值?

await ReceiptDetails.findAndUpdate(
    {patientIDnumber:patientIDnumber,
    appNum:appNum
    }, 
    {dateIssued:date, 
    addedItem: addedItemValue,
    paymentType:paymentType,
    totalAmount:totalAmount,
    officialReceiptNum:officialReceiptNum,
    addedProcedurePrice:addedProcedurePrice,
    amountPaid:amountPaid,
  }
  )

这是我唯一的选择。

nmpmafwu

nmpmafwu1#

使用updateMany()更新多条记录,api文档称该函数的响应有matchedCount、modifiedCount、upsertedId等字段,见下图:

const res = await Person.updateMany({ name: /Stark$/ }, { isDeleted: true });
res.matchedCount; // Number of documents matched
res.modifiedCount; // Number of documents modified
res.acknowledged; // Boolean indicating everything went smoothly.
res.upsertedId; // null or an id containing a document that had to be upserted.
res.upsertedCount; // Number indicating how many documents had to be upserted. Will either be 0 or 1.

相关问题