-
Type: Improvement
-
Resolution: Cannot Reproduce
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: Writes
We are facing an issue when dealing with "unique" indexes.
We have defined a unique index in a collection for field "field_id" using:
db.client.createIndex({"field_id": 1}, {unique: true})
If two rows with the same value for field "field_id" are inserted, the insert operation fails, as expected. However, the error message is not helpful at all:
com.mongodb.MongoBulkWriteException: [...] Write errors: [BulkWriteError{index=0, code=11000, message='E11000 duplicate key error collection: client index: field_id_1', details={}}]
As you can see, the error description does not specify which duplicate key is causing the issue.
Looking around, we have seen that other 11000 code errors include a "dup key" element in the error description, indicating which key caused it. Why aren't we getting this detail in the error description?
We are using this expression to write to the collection:
df.write.format("mongo").mode("append").option("uri", uri).save()
We have tried with different spark-connector versions but still get the same results.
mongo-spark-connector_2.11-2.4.3
mongo-spark-connector_2.12-3.0.1