Unique constraint with document lookup and counter question

Apologies that this got lost in the shuffle and we never responded.

The guidance provided in Can i do unique constraint on some attribute not the id would be the best approach.

There is no race condition because you’re not doing a lookup first…you’re doing the insert first which is atomic. If the insert fails, you know that a document with that key already exists.