I misunderstood what you said.
$set in an upsert sets the document to be upserted.
Here it is in PHP where I add a pot to a collection of pottery:
public function upsert_pot(object $doc): bool {
$doc['price'] = new MongoDB\BSON\Decimal128($doc['price']);
$uresult = $this->mongodb_db->pottery->updateOne(
['potnum' => $doc['potnum']],
['$set' => $doc],
[
'upsert' => true,
'writeConcern' => new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY)
]
);
return $uresult->getModifiedCount() > 0 || $uresult->getUpsertedCount() > 0;
}