The KeyPattern of a particular shard can be fetched using the following call.
ScopedCollectionMetadata collMetada; KeyPattern shardKeyPattern(collMetadata->getKeyPattern());
Hence, it is unnecessary that the split chunk command must take in a BSONObj called keyPatternObj, as in the following code block.
BSONObj keyPatternObj;
{
BSONElement keyPatternElem;
auto keyPatternStatus =
bsonExtractTypedField(cmdObj, "keyPattern", Object, &keyPatternElem);
if (!keyPatternStatus.isOK()) {
errmsg = "need to specify the key pattern the collection is sharded over";
return false;
}
keyPatternObj = keyPatternElem.Obj();
}
This keyPatternObj parameter can most likely be removed completely from the split chunk command.