Skip to content

Instantly share code, notes, and snippets.

@jaymecd
Created July 30, 2014 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaymecd/ceeff79ebabe8741162e to your computer and use it in GitHub Desktop.
Save jaymecd/ceeff79ebabe8741162e to your computer and use it in GitHub Desktop.
Simple CLI MongoDb query runner
#!/bin/sh
HOST="localhost"
DB="test"
QUERY="${1}"
if [ "x${QUERY}" == "x" ]; then
read -p "Query: " QUERY
fi
if [ "x${QUERY}" == "x" ]; then
echo " Aborted. No query to process..."
exit
fi
time mongo "${HOST}/${DB}" --quiet --eval "var res = ${QUERY}; shellPrint(res)"
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment