To avoid inserting the same document more than once, only use
upsert:true
if the
query
field is uniquely indexed.
The remaining operations would either:
update the newly inserted document, or
fail when they attempted to insert a duplicate.
If the operation fails because of a duplicate index key error, applications may retry the operation which will succeed as an update operation.
If all update() operations complete the query portion before any client successfully inserts data,
and
there is no unique index on the name field, then each update operation may perform an insert.