It's possible to hit this invariant as index key KeyStrings are created without their field names present in the KeyStrings.
For example, if we had the following document:
{ a: 1, b: 1 }and two indexes on keys "a" and "b", then the KeyStrings for the index keys of the document would be identical as the field name in the KeyString is not present. The BSON representation of this would look like: { : 1 } for both.
So to distinguish index key KeyStrings, we should append the index name to the end of them.