MongoDB “atomic” find entity and if not found update a different one

I am trying to solve a race condition issue through MongoDB operations so I can avoid the implementation of locks.

My goal is to be able to check if there is any document with a certain status in the collection and if not, to set that status to an existing document of the collection of my choice. That goal comes from the need that due to concurrency any implementation I tried makes that with a race condition I get more than one document updated.

Let me put a parallel example. In a scenario of concurrent calls, my goal is that the logic checks if there is not any existing Card that has status ACTIVE, a Card of my choice is set to ACTIVE, and if there is already an ACTIVE Card, to leave that as it is. All in just one MongoDB operation. This operation is triggered by a different flow so I can’t change the flow to set as ACTIVE a Card before executing that logic.

I tried through the use of the findOneAndUpdate (and even findOneAndReplace) operation:

const query = {
  userId: 'user-id-1',
  status: 'ACTIVE',
};

Card.findOneAndUpdate(
    query,
    {
        $set: {
            _id: 'chosen-id', // A certain chosen ID to update if not found.
            userId: 'user-id-1', 
            status: 'ACTIVE',
        },
    },
    {
        upsert: true,
        returnNewDocument: true,
    }
);

But I find myself unable to achieve my goal with any of the options available, therefore I only achieve to update a found Card. If not found, anything remains the same and my chosen Card is not set as ACTIVE. The only case is when adding like in the example upsert: true I can create a new document, but I do not want as I want to update a different existing document.

Has MongoDB any implementation that can achieve this behaviour in one single operation? Regardless of the version. I have no limitations in upgrading if needed.