0

I am aware that mongoose has findOneAndUpdate that can only filter one value. How can I filter two values?

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

These are the only option that I have. enter image description here

dape
  • 23
  • 5

1 Answers1

1

use updateMany() for updating multiple records, api doc says response of this function has fields such as matchedCount, modifiedCount, upsertedId etc, see below:

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.
  • I want to `filter` multiple values, not `update` the values – dape Nov 22 '22 at 17:17
  • by using `findbyOne`, I can only filter `patientIDnumber:patientIDnumber` and I want to filter both `patientIDnumber:patientIDnumber` and `appNum:appNum` – dape Nov 22 '22 at 17:19
  • 2
    in your question you have said findAndUpdate, which is confusing, if you want to query data, you should be using find api as suggested by @luís-mestre – Harsh Vishwakarma Nov 22 '22 at 17:28
  • I am using find function now thank you! – dape Nov 22 '22 at 19:02