Is it possible/ how to perform upsert on a sharded MongoDB cluster

I’d like to perform an upsert operation on a sharded MongoDB cluster, but I get the exact same error for every variation I try. When I write this way to a local standalone Mongo, it works perfectly, but on the sharded cluster I get the errors.

My cluster currently has the structure of a unique (obviously) id at the _id field, and another (also unique) id at the itemId field - which is the sharded key. I’m using Reactive Spring Data, but I’ve managed to restore the same error on the CLI of this sharded Mongo instance.

The error was Failed to target upsert by query :: could not extract exact shard key. My queries were variations of this query:

db.MyCollection.updateOne({"_id": "a2","itemId": "a2"}, 
{"$set": {"itemId": "a3"}}, 
{upsert: true},
{multi: false})

Also when I don’t update the sharded field, the error remains the same:

db.MyCollection.updateOne({"_id": "a2","itemId": "a2"}, 
{"$set": {"itemColor": "brown"}}, 
{upsert: true},
{multi: false})

updateMany() \ multi: true variations didn’t work as well. This page wasn’t very helpful too.

I’ve read suggestions of adding the @Sharded annotation so that Spring will automatically add the sharded key to the filter, but since I did it manually I didn’t find that helpful.

Any reason why this can happen? Or what this error even means?

I’m using version 5.0.