Skip to content

Instantly share code, notes, and snippets.

@todvora
Created May 20, 2015 05:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todvora/27a3b7055e464eef1439 to your computer and use it in GitHub Desktop.
Save todvora/27a3b7055e464eef1439 to your computer and use it in GitHub Desktop.
Variety.js - analyze all available collections
#!/usr/bin/env bash
# the database name, that will be analyzed
DATABASE_NAME="test"
# read all collection names, using mongo shell
COLLECTIONS=$(mongo $DATABASE_NAME --eval "db.getCollectionNames().join('\n');" --quiet)
echo -e "Found collections: \n$COLLECTIONS"
# iterate over the collection names
while read -r collection; do
echo
echo "Collection '$collection':"
# analyze every collection, no other options specified. Output is set to --quiet, no debug info will be printed,
# only ascii table with the analysis.
mongo $DATABASE_NAME --quiet --eval "var collection = '$collection'" variety.js
echo
done <<< "$COLLECTIONS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment