Query for upserting data but update should happen only if condition is true

Hello,

If we have a DB model as

{
    name: string;
    quantity: number;
    status: string;
}

Is it possible to write an updateOne query with upsert true, so that

  1. If filter doesn’t match name, it will insert a new entry with name, status and quantity.
  2. If filter does match and status is ‘PROCESSED’ it will NOT perform any update
  3. If filter does match and status is NOT ‘PROCESSED’ it will update the quantity

I’m struggling with points 2 and 3.

Thank’s for the help.

According to the manual, updateOne can’t support all these in one call.
But if you need atomic guarantee, you can try transaction.