// "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 + "]";

}

@@ -267,45 +267,9 @@
     
-var maxNameLength = maxLength(db.getC
+c
 olle
@@ -282,20 +282,10 @@
 ames
-());%0A      
  
+=
  db.
@@ -310,14 +310,13 @@
 ().f
-orEach
+ilter
 (fun
@@ -350,16 +350,18 @@
         
+  
 // exclu
@@ -417,20 +417,26 @@
         
-if (
+  return !
 collecti
@@ -467,52 +467,48 @@
 m.')
-) %7B return ; %7D%0A          var c
+;%0A        %7D);%0A        documentC
 ount
+s
  = 
-db.getC
+c
 olle
@@ -516,147 +516,111 @@
 tion
-(collectionName).count();%0A%0A          print(%0A            colorize(collectionName.pad(maxNameLength, true), %7B color: 'green', bright: true %7D)
+Names.map(function (collectionName) %7B%0A            var count = db.getCollection(collectionName).count();
 %0A   
@@ -632,17 +632,16 @@
     
-+ %22  %22 + 
+return (
 coun
@@ -668,27 +668,27 @@
 ment(s)%22
-%0A  
+);%0A
         
 );%0A     
@@ -679,16 +679,17 @@
         
+%7D
 );%0A     
@@ -683,33 +683,82 @@
     %7D);%0A        
-%7D
+printPaddedColumns(collectionNames, documentCounts
 );%0A        retur

Refactor `count docs` to use printPaddedColumns()