Skip to content

Instantly share code, notes, and snippets.

@piercemoore
Last active December 17, 2015 17:09
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 piercemoore/5644400 to your computer and use it in GitHub Desktop.
Save piercemoore/5644400 to your computer and use it in GitHub Desktop.
Aliases for Shortcuts in MongoDB/Redis
### The commands
# Show all collections and the number of documents in each
mongo zngine_dev --eval "printjson(db.getCollectionNames().forEach(function(coll){printjson(coll+\"-\"+db[coll].count())}))"
# Drop all collections and remove all indexes from mongo
mongo zngine_dev --eval "db.getCollectionNames().forEach( function(coll) { if(coll!=\"system.indexes\") { db[coll].drop(); db[coll].dropIndexes(); } } )"
# Count all Redis keys
redis-cli keys "*" | wc -l
# Clear all Redis keys
redis-cli flushall
# Zngine-specific mongo queries
alias z_admins='mongo zngine_dev --eval "db.admins.find().limit(5).forEach(printjson)"'
alias z_owners='mongo zngine_dev --eval "db.owners.find().limit(5).forEach(printjson)"'
alias z_profiles='mongo zngine_dev --eval "db.profiles.find().limit(5).forEach(printjson)"'
### *Nix aliases for these commands
alias mongocount='mongo zngine_dev --eval "printjson(db.getCollectionNames().forEach(function(coll){printjson(coll+\"-\"+db[coll].count())}))"'
alias mongokill='mongo zngine_dev --eval "db.getCollectionNames().forEach( function(coll) { if(coll!=\"system.indexes\") { db[coll].drop(); db[coll].dropIndexes(); } } )" && mongocount'
alias rediscount='redis-cli keys "*" | wc -l'
alias rediskill='redis-cli flushall'
# Zngine-specific mongo queries
alias z_admins='mongo zngine_dev --eval "db.admins.find().limit(5).forEach(printjson)"'
alias z_owners='mongo zngine_dev --eval "db.owners.find().limit(5).forEach(printjson)"'
alias z_profiles='mongo zngine_dev --eval "db.profiles.find().limit(5).forEach(printjson)"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment