// "count documents", a bit akin to "show collections"
shellHelper.count = function (what) {
    assert(typeof what == "string");

    var args = what.split( /\s+/ );
    what = args[0]
    args = args.splice(1)

    if (what == "documents" || what == "docs") {
        var maxNameLength = maxLength(db.getCollectionNames());
        db.getCollectionNames().forEach(function (collectionName) {
          // exclude "system" collections from "count" operation
          if (collectionName.startsWith('system.')) { return ; }
          var count = db.getCollection(collectionName).count();

          print(
            colorize(collectionName.pad(maxNameLength, true), { color: 'green', bright: true })
            + "  " + count.commify() + " document(s)"
          );
        });
        return "";
    }

    throw "don't know how to count [" + what + "]";

}

// "count documents", a bit akin to "show collections"
shellHelper.count = function (what) {
    assert(typeof what == "string");

    var args = what.split( /\s+/ );
    what = args[0]
    args = args.splice(1)

    if (what == "documents" || what == "docs") {
        collectionNames = db.getCollectionNames().filter(function (collectionName) {
            // exclude "system" collections from "count" operation
            return !collectionName.startsWith('system.');
        });
        documentCounts = collectionNames.map(function (collectionName) {
            var count = db.getCollection(collectionName).count();
            return (count.commify() + " document(s)");
        });
        printPaddedColumns(collectionNames, documentCounts);
        return "";
    }

    throw "don't know how to count [" + what + "]";

}

Refactor `count docs` to use printPaddedColumns()