#!/bin/sh
#
authDB="xxx"
DBHost="192.168.0.xx"
DBPort=27017
DBUser="root"
DBPasswd='xxxxxx'
DBName='xxxx'         # which database of we want tables count

dbShell="mongo --quiet --authenticationDatabase ${authDB} --host ${DBHost} --port ${DBPort} -u ${DBUser} -p${DBPasswd}"

find_tables() {
$dbShell  <<EOF
use ${DBName}
show tables
EOF
}


table_count() {
find_tables | grep -v "switched to db" | while read line ;do
  echo "table $line count is:"
  $dbShell <<EOF
use ${DBName}
db.getCollection("$line").count()
EOF
done
}

table_count | grep -v "switched to db"
