When we attempt to index a document that is ambiguous for the key pattern {‘a.0’: 1}, BtreeKeyGenerator::_extractNextElement() includes the contents of the array field in the uassert error message, with error code 16746. When the command processing subsystem converts this UserAssertion into a Status for the createIndexes command result, the result may exceed the 16 MB BSON document limit, leading to a different error code BSONObjectTooLarge returned in the final result. This obscures the original source of the indexing error.
To reproduce:
// Add a small document first. We cannot transmit a document larger than the 16mb over the wire. const dupDoc = {a: [{'0': 1}]}; t.save(dupDoc); // This extends the array with nulls before append the requested integer. // The 1,5000,000 constant is based on a limit defined in path_support.h t.update({}, {$set: {'a.1500001': 1}}); // This should fail with an error code of 16746 instead of BSONObjectTooLarge. t.ensureIndex({'a.0': 1});