Before I update the document, I want to first retrieve the value of the existing document, such as:
document A:
{
id: 22893472347102,
apple: 3,
count: 5
}
I want to update {apple: 5, count:3} to document A, if apple in document A == 3, else insert {apple: 2, count:5}.
Is there any way to do it faster without doing query + insert(two action)?
I want to update, but base on the existing document content to update, I don’t want to use .find then use .updateOne, is there any faster solution that I can base on existing document to update?
Doing a find() then an updateOne() is definitively the wrong way to do it.
Yes there is. But with the scarce details of what you exactly want to do, the only thing we can do is to send you to the documentation on update operators: