You can use $setOnInsert like,
db.companies.updateOne(
{"company": "test"},
{ $setOnInsert: { "name": "nameVal2", ... } },
{ upsert: true }
)
If this update operation does not do insert, $setOnInsert won’t have any effect. So, the name will be updated only on insert.