Hello @Christina_Sandberg, welcome to the MongoDB Community forum.
I have an index in collection “persons” which shall avoid inserting duplicate documents with the same person name.
That is the Unique Index on the person’s “name” field. This will not allow an operation to insert a new document with an existing name or update a document with an updated existing name. If such an operation is tried it fails with an "E11000 duplicate key error collection: database.collection index_name … ".
As long as the name is unique within the collection, the name is inserted (or updated).
I suggest that you share the data and code (the scenario in detail) which you think is causing the problem.