When an insert produces a DuplicateKey error on a clustered collection whose _id is a Decimal128, the server throws an uncaught KeyString format error, either 50810 for values >=1 or 50825 for values < 1.
Root cause
A clustered collection's RecordId is the KeyString encoding of _id with the TypeBits intentionally discarded, the type information lives only in the document body as mentioned on this comment.
When there is a write conflict, to produce a user-friendly duplicate-key message, the insert path decodes the existing RecordId back to BSON. That decode runs with an empty TypeBits that is represents of kInt. When the values carry decimal-format markers then we throw in toBsonValue().
- related to
-
SERVER-130009 Create a property-based test for collections clustered on _id
-
- Blocked
-